473,387 Members | 1,582 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.

Determine proper width of Label?

Hi,

A Windows form that I'm developing will have two controls: Label1 and
Label2. Both controls are of type Label (go figure). The text of Label1 will
not be known until runtime and may change at times. When the MyText property
of the containing form is set, I want to:

a) Set the Label1.Text property appropriately.
b) Change the width of Label1 so that it is exactly wide enough to show
the text.
c) Move Label2 so that its left edge is equal to Label1's right edge +
1.

Steps (a) and (c) are easy, but I'm not sure how to approach step (b).
Given a string, how do I set the width of Label1 to a value that is exactly
large enough to show the string?

David
Nov 15 '05 #1
2 2064
Hi David,

Labels have an AutoSize property.

Regards,
Fergus
Nov 15 '05 #2
Thanks, guys.. I had no idea that the Label.AutoSize property even
existed. I was just about to implement my own solution using
Graphics.MeasureString(), but clearly setting AutoSize to true is the way to
go. Thanks again!

David

"David Sworder" <ds******@cts.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Hi,

A Windows form that I'm developing will have two controls: Label1 and
Label2. Both controls are of type Label (go figure). The text of Label1 will not be known until runtime and may change at times. When the MyText property of the containing form is set, I want to:

a) Set the Label1.Text property appropriately.
b) Change the width of Label1 so that it is exactly wide enough to show the text.
c) Move Label2 so that its left edge is equal to Label1's right edge +
1.

Steps (a) and (c) are easy, but I'm not sure how to approach step (b).
Given a string, how do I set the width of Label1 to a value that is exactly large enough to show the string?

David

Nov 15 '05 #3

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

Similar topics

2
by: Alex Shi | last post by:
In php, is there a way obtain the width of a charactor of a certain font? Alex -- ================================================== Cell Phone Batteries at 30-50%+ off retail prices!...
8
by: Mario T. Lanza | last post by:
I'm not sure what I'm doing wrong. I have a form that has mnay input fields. Before each input field is a label enclosed in custom LABEL tags. Inside my CSS I have: LABEL { width: 120px; }
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
3
by: Andre | last post by:
Hi, Did someone know why this code does'nt work (The TableCell Width). The cell don't have 600 and 150 like writed in width="600" and width="150". <asp:datagrid id="DataGrid1" ...
2
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat...
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? ...
5
by: BobLaughland | last post by:
Hi There, I am trying to get some fields to align on a web page, like this, To: From: Subject: Each of the fields above have a corresponding asp:Textbox control next to it that I cannot...
7
by: Chris Riesbeck | last post by:
What's the right way to make sure checkboxes stick with their labels when the window is resized? Right now I'm trying <label><input ...text</labelwith white-space:nowrap on label, but this only...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.