form height?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

form height?
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
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: form height?
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.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: form height?
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 ;)
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
3 posts Page 1 of 1
Return to “Coding Help & Support”