PC Review


Reply
Thread Tools Rate Thread

Determine proper width of Label?

 
 
David Sworder
Guest
Posts: n/a
 
      29th Aug 2003
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


 
Reply With Quote
 
 
 
 
Fergus Cooney
Guest
Posts: n/a
 
      29th Aug 2003
Hi David,

Labels have an AutoSize property.

Regards,
Fergus


 
Reply With Quote
 
David Sworder
Guest
Posts: n/a
 
      29th Aug 2003
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" <(E-Mail Removed)> wrote in message
news:%23%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine width of entire visible area and width of labels david.j.winfield@gmail.com Microsoft Excel Programming 2 20th Mar 2008 03:51 AM
proper char width bj Microsoft Dot NET Framework Forms 1 5th Nov 2003 04:30 PM
Proper way to determine socket state? Mike Hildner Microsoft Dot NET Framework 0 10th Oct 2003 06:14 PM
Determine proper width of Label? David Sworder Microsoft C# .NET 2 29th Aug 2003 06:15 PM
Set label width to string width PontiMax Microsoft Dot NET Framework Forms 0 4th Aug 2003 03:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 AM.