How do I autosize the TEXT?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheGuyInUrCloset
    New Member
    • Dec 2009
    • 2

    How do I autosize the TEXT?

    I have a box that has a predetermined size. Is there anyway I can automatically size the text to make it the largest it can, while still fitting inside the label's size? I cannot auto size the label, the label needs to stay the same size, I just need to resize the text.

    Thanks to all that help!
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Take a look at the Graphics.Measur eString method. Perhaps you can use it to figure out how big your textbox needs to be.

    Comment

    • TheGuyInUrCloset
      New Member
      • Dec 2009
      • 2

      #3
      I was trying that, but it said I was missing an event handler. Which Using directive do I need to add? If I read right it said Paint, but I could not find it. Sorry if this is a really simple answer, this is my first application I am trying to build, so I am brand new to C#.

      EDIT: Nevermind. I think I found it.
      Last edited by TheGuyInUrCloset; Dec 31 '09, 08:49 PM. Reason: Found Answer

      Comment

      • vishal1082
        New Member
        • Apr 2009
        • 92

        #4
        I suppose that the Label's (that contains the text you wanna resize) name is label1.

        Code:
        System.Drawing.SizeF size = label1.CreateGraphics().MeasureString("the text i wanna measure", label1.Font);
        this will return a System.Drawing. SizeF struct object, that has width and height of the text, now check if the width of text is more than label's width
        Code:
        if(size.Width > label1.Size.Width)
        {
        //...you can reduce the font size here according to the size of text and label's size.
        }

        Comment

        Working...