Page 1 of 1

form height?

Posted: Sat Mar 17, 2018 10:47 am
by Dummy1912
hello,

i like to resize the form just to display the label1 text to adjust the size to display
so the default form height = 254
so we like to get the form height just high enough to display the text inside the label1

if more text in label1 to higher the form will be
the less text in label1 the smaller the form will be

Code: Select all
        Dim w As Integer = label1.Width
        Dim h As Integer = CalculateHeight()
        Me.Height = h / 2 - label1.Text.Length

    Private Function CalculateHeight() As Single
        Dim g As Graphics = label1.CreateGraphics
        Return g.MeasureString(label1.Text, label1.Font).Width
    End Function

Thanks

Re: form height?

Posted: Sat Mar 17, 2018 2:18 pm
by CodenStuff
I'm not sure exactly what you are trying to accomplish here?

If your form only contains the label control, the form is border-less and the label is at point 0,0 on the form (top-left corner) then you should just be able to use:
Code: Select all
Me.Height = Label1.Height
Which would make the form height the same height as the label.

If this is not what you are doing please explain a little bit more.

Re: form height?

Posted: Sun Mar 18, 2018 10:48 am
by Dummy1912
Hello,

Not that really what we want.

We need to resize the height and width of the form
with the text of label1

its like a messagebox it expand or shrink to display the text label1 so it show all to read easier

hope this helps ;)