Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want my Label control to right align, when I set TextAlign to MiddleRight, but it is not to work, why is it? What can i do to solve it? Thanks.
Posted

Try setting AutoSize property of the Label to false.
See if it works.
 
Share this answer
 
Comments
hardworkerstudio 27-Mar-24 8:42am    
Thanks!!!
check 3 possibilities
1. Autosize property = false (as given in solution 1)
2. check in code that some where alignment of that label is reset/overlapping
3. build application without error
you can use 'improve question' or 'post comments' for problems regarding same question.
Happy Coding!
:)
 
Share this answer
 
v2
Comments
Andrewpeter 24-Aug-12 2:13am    
Thank you very much for your answer, if I change AutoSize property into false then the Label is multi-lines, but i want it is not multi-lines. How to do this? Thanks.
Aarti Meswania 24-Aug-12 2:26am    
set label's height manually as label allow only 1 row.
Andrewpeter 24-Aug-12 2:37am    
When text width is larger than Label width then superfluous text doesn't display, you can try this! Another solution? Thanks.
Couple of points:
1. Change the AutoSize property. Default it is set to True. Change it to False.
2. Increase the size of the label to know, whether the TextAlign is working properly or not. For example, change Margin to (15, 0, 15, 0) and Size value to (175, 36)
3. You need to set TextAlign property. TextAlign might contain any of the following values,
TopLeft    | TopCenter    | TopRight
MiddleLeft | MiddleCenter | MiddleRight
BottomLeft | BottomCenter | BottomRight

The default value is TopLeft. You can choose the value according to your need.
 
Share this answer
 
i assume you use windows form,in that case you need to see label's anchor property.set right to it's anchor..and it will work
 
Share this answer
 
hello,


i think you should insert your labels in tag ,see below,


C#
<pre>
<span style="float:right"><asp:lable id="label2" xmlns:asp="#unknown"></asp:lable></span>  

this will display right align,


hope this will help you
 
Share this answer
 
Attach an event handler to the labels' SizeChanged event:

C#
private void label1_SizeChanged(object sender, EventArgs e)
{
    label1.Location = new Point(Your_Anchor_Point - label1.Width, label1.Location.Y);
}


To be more DPI friendly consider using some other control as the anchor point, i.e.

C#
label1.Location = new Point(dataGridView1.Location.X + dataGridView1.Width - label1.Width, label1.Location.Y);


to align to the RH side of the dgv.

(BTW: I tried the Paint & TextChanged events but they seemed to sometimes get confused - probably something to do with event order particularly on opening a new form.)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900