What is an efficient way to resize a label so its smaller than the parent container?
I'm looking for a way to insert a label into a flowlayoutpanel without it having to scroll horizontally. Therefore, autosize is out of the question. I have it right now so it doesn't exceed the flowlayoutpanel using the code:
Code:
newlabel.Width = Parent.Width - (newlabel.Width / 2)
But I still can't figure out how to size it vertically. I need to make it so the label is only slightly longer than the last line of text. What is the most efficient way to try to accomplish this?
Re: What is an efficient way to resize a label so its smaller than the parent contain
This will give you the drawn size of the label - you should be able to use it to check the bounds of the label (and act accordingly):
vb Code:
Dim szF As SizeF = Me.Label1.CreateGraphics.MeasureString(Me.Label1.Text, Me.Label1.Font)
MsgBox(szF.Width.ToString & " " & szF.Height.ToString)
Re: What is an efficient way to resize a label so its smaller than the parent contain
Quote:
Originally Posted by
Chris147
This will give you the drawn size of the label - you should be able to use it to check the bounds of the label (and act accordingly):
That's nearly right but it's a multiline label. All you need to do is add the target width of the label as the next argument:
Code:
Dim szF As SizeF = Me.Label1.CreateGraphics.MeasureString _
(Me.Label1.Text, Me.Label1.Font, Label1.Width)
Then it will allow for word-wrapping of the text.
BB
Re: What is an efficient way to resize a label so its smaller than the parent contain
You see, that's why I like tech forums - thanks BB, I learned something today.
Chris.