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.
4 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: 4390
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
CodebrewVB
Just Registered
Just Registered
Posts: 2
Joined: Tue Jun 25, 2024 5:02 am

Re: form height?
CodebrewVB
I get it. You want to resize the form based on the value of the label. I was able to figure out the form matching and wrapping with the text for the height. The width I'm having a hard time perhaps someone else can shine some light.

Example 1:
Image
Example 2:
Image
Code:
Code: Select all
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.FormBorderStyle = FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Label1.AutoSize = True
        Label1.MaximumSize = New Size(Me.ClientSize.Width - 20, 0)
        Label1.Location = New Point(10, 10)
        Label1.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam bibendum, enim malesuada pretium hendrerit, purus quam consequat felis, nec pellentesque lorem nulla sit amet risus. Donec tristique sagittis tortor, sed laoreet quam volutpat vel. Phasellus sollicitudin egestas tincidunt. Phasellus et metus turpis. Vestibulum vel tellus quis erat mattis tempor at vitae augue. Nam sit amet imperdiet est, in sagittis mauris. Nunc quis quam venenatis, placerat eros nec, ultrices dui. Morbi tortor eros, auctor nec dolor eget, rhoncus finibus odio. Ut vestibulum ante ut augue convallis imperdiet. Vivamus magna felis, faucibus a viverra non, eleifend vel quam. Aenean congue risus elit, a aliquam ligula rutrum condimentum. Phasellus elementum leo non libero venenatis tincidunt. Mauris et vestibulum ligula, eu pharetra libero. Etiam bibendum vehicula auctor. Etiam ultricies ullamcorper nibh, sed tristique mi elementum id. Donec condimentum vel purus sed commodo. Proin a neque mi. Duis gravida convallis nulla, eget tincidunt purus auctor vitae. Vestibulum ex neque, auctor eu eros non, facilisis posuere nibh. Ut luctus sagittis sapien id vehicula. Aliquam lobortis pulvinar purus, et ultrices metus varius a. Duis egestas nec leo vel lobortis. Nulla mattis tincidunt enim, eget congue eros congue eget. Integer sollicitudin leo vitae nunc sodales, eu fringilla mi rhoncus. Nullam id ultrices tellus, at molestie diam. Vestibulum tincidunt urna at pretium hendrerit. Nullam sed nulla vulputate, auctor massa at, tempus ipsum. Donec congue neque nisl, ac facilisis tortor hendrerit quis. Praesent at viverra enim. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non nulla leo."
        AdjustFormHeight()
    End Sub

    Private Sub Label1_TextChanged(sender As Object, e As EventArgs) Handles Label1.TextChanged
        AdjustFormHeight()
    End Sub

    Private Sub AdjustFormHeight()
        Me.ClientSize = New Size(Me.ClientSize.Width, Label1.Height + Label1.Top + 40)
    End Sub
End Class
Hope this works on your end :)
4 posts Page 1 of 1
Return to “Coding Help & Support”