We help IT Professionals succeed at work.
Get Started

How can I make a fixed width autosizing label?

3,102 Views
Last Modified: 2013-11-26
I want to make a label that will wrap text and expand down but where I can give it a fixed width... the only way I've come up with to do this so far is to use a txtbox with this code:

    Private Sub Test_ResizeEnd(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ResizeEnd
        txtPrompt.Height = 13 * System.Math.Truncate(txtPrompt.PreferredSize.Width / txtPrompt.Width) + txtPrompt.PreferredSize.Height
    End Sub

Open in new window



This works 99% but depending on the length of words it rarely will find a combination where the height is calculated wrong.
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE