Is there any way I can get the height of a label, if it hypothetically had a certain width?
I've been trying with control.GetPreferredSize(size)
like so:
Dim wantedWidth as Integer = 100
dim ctrlSize as Size = label.GetPreferredSize(new Size(wantedWidth, 0))
because I thought that setting height = 0
, would indicate a free height, but the height I get is way too small. I also tried to estimate the height of the label, using Graphics.MeasureString
to calculate the equivalent area of the Label
dim prefWidth as Integer = 100
dim estSize as SizeF = g.MeasureString(label.Text, label.Font)
dim estHeight as Integer = (Integer)(estSize.Width * estSize.Height / prefWidth)
but that yields the same result. Any ideas? I'm on .NET 2.0, unfortunately.