like this?
Label1.width = 100dip
Label1.Height = Label1.Width - 2dip
The trick is to adjust the label to the proper height to accommodate the text. Otherwise you will see only the top half of the text.
A label may be initially defined as 20dip, but it may not be high enough for the current TextSize, Typeface, or when the number of lines of text is changed. The text will get truncated and that is not good. Labels can be very very finicky when displaying text.
In your example, you create a label that is almost square. This won't work if the label has a colored background (too large) or the label has a click event because if the label background color is transparent, when the user clicks well below the visible text, it will still trigger the Label_Click event. The height of the label must be just right to accommodate the text that it contains and there are 2 ways to do it.
Label1.Height = -2 'Auto adjust label height to fit the text
or
Label1.Text = "Some New Text"
ResizeLabelHt(Label1) 'Use the code below every time the text, typeface, textisize changes
Sub ResizeLabelHt(aLabel As Label)
If aLabel.IsInitialized And aLabel.Parent <> Null Then
Private SU As StringUtils 'Should make SU a global variable
Private NewHt As Int
NewHt = SU.MeasureMultilineTextHeight(aLabel, aLabel.Text)
If aLabel.Height <> NewHt Then
aLabel.Height = NewHt
End If
End If
End Sub
I have included a small test app to show the two approaches.
Which is better? I don't really know. They both create labels of exactly the same dimensions.
There may be a reason for not using Label1.Height=-2 so the label height is auto-adjusted.