Reputation: 113
I'm making an application in VB.NET and I have a control (a label to be specific) and it's been set to auto size based on the texts in it. Currently, the label box resizes to the left and down:
[Label] ->
|
v
I want the label to resize to the right and down:
<-[Label]
|
v
How would I do this?
Edit: the label display's the windows account name. It's aligned to the right side of the window, so that's why the text must be autosized and expand to the left rather then the right.
Upvotes: 0
Views: 1392
Reputation: 6948
The only way I can think of is to adjust the location according to the change in size. Here's some code that will do that. I used the Tag property to hold he current size before the resize. then in the Resize event handler adjusted the location. Whenever the label's text is changed the tag gets the size. When the resize is called the size has changed and comparing the 2 will tell us how much to change the location. since the defaul autosize operation is already down I didn't change that.
Private Sub Label1_TextChanged(sender As System.Object, e As System.EventArgs) Handles Label1.TextChanged
Label1.Tag = Label1.Size
End Sub
Private Sub Label1_Resize(sender As System.Object, e As System.EventArgs) Handles Label1.Resize
Dim TempSize As New Size(New Point(0))
If Label1.Tag Is Nothing Then Label1.Tag = Label1.Size
TempSize = DirectCast(Label1.Tag, Size)
Label1.Location = New Point(Label1.Location.X - (Label1.Size.Width - TempSize.Width), Label1.Location.Y)
End Sub
Upvotes: 1
Reputation: 5719
I want the label to resize to the right and down:
Set label's property
Autosize = False
TextAlign = TopRight
Upvotes: 0