Label AutoSize Behaves Differently from VB6

  • Thread starter Thread starter Charles Law
  • Start date Start date
C

Charles Law

I have noticed that the label control in .NET doesn't work quite the same as
it used to do.

It used to be possible to set it to auto-size in such a way that the width
remained constant and the height varied according to the amount of text in
the control.

Have I missed a setting somewhere or is there another way of doing it now?

TIA

Charles
 
Charles Law said:
I have noticed that the label control in .NET doesn't work quite the same
as it used to do.

It used to be possible to set it to auto-size in such a way that the width
remained constant and the height varied according to the amount of text in
the control.

Have I missed a setting somewhere or is there another way of doing it now?

\\\
Me.Label1.Text = "Hello Bla World Foo Goo Bloo Hoo Joo..."
Dim g As Graphics = Me.Label1.CreateGraphics()
Me.Label1.Height = _
CInt( _
g.MeasureString( _
Me.Label1.Text, _
Me.Label1.Font, _
Me.Label1.Width _
).Height _
)
g.Dispose()
///
 
Hi Herfried

You read my mind ... or I read yours :-)

After posting, I got on and created a user control called AutoLabel,
inherited from Label, and included the self same code in the OnResize
method, et. al. I reckoned that it would be as effective as the original,
and it was.

Cheers.

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top