473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Label AutoSize Behaves Differently from VB6

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
Nov 21 '05 #1
2 1247
"Charles Law" <bl***@nowhere.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eH****************@TK2MSFTNGP10.phx.gbl...
"Charles Law" <bl***@nowhere.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Harvey | last post by:
Hello: I am trying to use Autosize=true on a long string and it extends off of my form, rather than increasing the number of lines of the Label as the documentation says it should do. Would...
0
by: Adonai | last post by:
Hi, I'm having an issue with this code that I'm writing, I'm curious as to why the windows form label (lblTime) isn't getting updated with the new variable when I use the timer. I made a blank form...
1
by: Weber Samuel | last post by:
Hi NG i try to catch the Application.Idle Event: --> Application.Idle += new EventHandler(OnIdle); Here's my problem: If i put a Label on my Form and set the Property AutoSize = true then...
2
by: Oenone | last post by:
I'm trying to create a form similar to a VB messagebox but with custom content. One of the things I want to be able to do is display some text in a label at the top of the messagebox form and have...
1
by: ngreplies | last post by:
I am using a label as a tooltip box because I need to be able to change the background of the box depending on the information it is representing. That aside, I need to be able to auto-size the...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
1
by: Patrick Lioi | last post by:
Label label = new Label(); label.Width = 1; label.AutoSize = true; label.Text = "A long string, requiring a width larger than 1."; //At this point, Width is still 1. What am I missing? ...
11
by: Peter Larsen [] | last post by:
Hi, I have two questions related to the Label control. How do i prevent the label from expand the canvas into 2 lines (word wrap) ?? At the moment i set AutoSize to false (to prevent the word...
6
by: Miro | last post by:
Is there a way to / or a mathematical formula to see if a font size is 'too big' for a label. I have a label that is docked to 'fill' a form, and I want to resize that font based on the width...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.