Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining Label control text alignment 1

Status
Not open for further replies.

morelab

Programmer
Dec 3, 2004
6
0
0
US
I am using a For-Next loop through all panel controls to print out a screen. I have everything working except the alignment of the text within the label.

Does anyone know how to obtain the text alignment property of a Label control?

Regards,
Bill
 
take a look at the textalign property. i.e. label1.textalign = middleright.
 
Pweegar -

That definitely works while you are creating the Label and want to set the alignment. I am, however, trying to get the text alignment of a Label that has already been created. There is no such property as textalign on the control.

For example, here is a sample line for how I get the starting X location of the already created Label:

Dim labelLocationX As Integer = ctl.Location.X

Nothing similar seems to exists to get the Text Alignment of the Label.

Any help is greatly appreciated.
 
TextAlign - Gets or sets the alignment of text in the label.

according to the 2k2 .Net help... should work at run time too.

Debug.WriteLine(Label1.TextAlign)

prints "TopLeft" to the output window.

-Rick

----------------------
 
I tried this:

Dim labelAlignment As String = ctl.TextAlign

And got a squiggly line under ctl.TextAlign. The hover error says:

'TextAlign' is not a member of 'System.Windows.Forms.Control.'

Any thoughts?
 
try this:

Code:
Dim labelAlignment As String = ctype(ctl,label).TextAlign

control doesn't have a TextAlign property, but Label does. Just make sure that ctl is infact a label.

-Rick

----------------------
 
That worked perfectly.

Thanks. I appreciate your help.
 
Hi, I'm looking at the code that thatrickguy used in order to add functionality to a control. It may help me with what I'm doing.

I'm looking to be able to set the scroll position in a textbox. Unfortunately the textbox control does not include an .Autoscroll function which would let me set the x and y points. Any idea of how I could do this?

 
I ran into that same issue when I first started working with .Net. I think it might have been something as simple as setting the cursor position of the text box.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top