• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2025 Replies
  • 331 Replies
    1928 Replies

form height?

Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
User avatar
Dummy1912
VIP - Donator
Posts: 1959

form height?

Sat Mar 17, 2018 11:47 am

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

User avatar
CodenStuff
Site Admin
Posts: 4367

Re: form height?

Sat Mar 17, 2018 3:18 pm

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.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.

User avatar
Dummy1912
VIP - Donator
Posts: 1959

Re: form height?

Sun Mar 18, 2018 11:48 am

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 ;)

Post Reply

Return to “Coding Help & Support”