CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Label Width

  1. #1
    Join Date
    Oct 2003
    Posts
    72

    Label Width

    A simple question:

    I have to put a string into a label control.
    From a cs file how can I resize the width of the label control according to the string's lenght?

    Thanks in advance

  2. #2
    Join Date
    May 2004
    Location
    Greenville, NC
    Posts
    193

    Re: Label Width

    I believe you can just set the label's AutoSize attribute to true, and it'll autosize automatically. I can't test it right now, but I'm fairly confident it works.
    Jason Isom
    .NET 2.0 / VS2005 Developer

  3. #3
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Label Width

    Graphics.MeasureString will do the job.
    Inherit from Label, Override the OnPaint method and you have e.Graphics in the EventArgs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured