Label Question

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
Hello all,

I have a label that must be centered. I am using a textbox on one form that is connected to the label via my.settings. When the user puts in a few words in the textbox the label on the other form dosn't appear centered under the labels above it.

I tried to use - text align, dock, anchor, and right to left properties, however, I can't get it right. What I would like to do is have the label filled from center out, but don't know what to do.

The only way the label looks centered is if the user puts in enough letters to make the label wider, but if the user puts just a few in there then it's off centered.

I have made the label move at runtime, but the user may not know that they can move it around on the form.

I hope this is not confusing and would like some help.......

Thanks

daveofgv
 
To center a control in a container (the form in this case) you take half of the control's width minus half of the form's width. IE: Label.Left = CInt((Me.Width / 2I) - (Label.Width / 2))

Another way to do this is to turn off AutoSize and stretch the label to span the entire width of the form and have it's text alignment set to TopCenter, MiddleCenter or BottomCenter
 
To center a control in a container (the form in this case) you take half of the control's width minus half of the form's width. IE: Label.Left = CInt((Me.Width / 2I) - (Label.Width / 2))

Another way to do this is to turn off AutoSize and stretch the label to span the entire width of the form and have it's text alignment set to TopCenter, MiddleCenter or BottomCenter
VB.NET:
Label1.Left = Me.Width \ 2 - Label1.Width \ 2
Integer division is nicer.

There's also the option of using a TableLayoutPanel.
 
Back
Top