Results 1 to 4 of 4

Thread: How to text wrap with label in winforms

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    How to text wrap with label in winforms

    I don't know much about software development. I am trying to learn with it... I am recently stuck at a place where i don't know How to text wrap with label in winforms???? Can someone Help Please...??

  2. #2
    Join Date
    Apr 2008
    Posts
    1,949

    Re: How to text wrap with label in winforms

    Here control is a customized label that fits its height automatically. To add a new class to its project, to stick the code that appears next and to construct its project. Now it can loosen to a GrowLabel the control of the part superior of the toolbox in his form.

    Code:
    using System;
    using System.Text;
    using System.Drawing;
    using System.Windows.Forms;
    
    public class GrowLabel : Label {
      private bool mGrowing;
      public GrowLabel() {
        this.AutoSize = false;
      }
      private void resizeLabel() {
        if (mGrowing) return;
        try {
          mGrowing = true;
          Size sz = new Size(this.Width, Int32.MaxValue);
          sz = TextRenderer.MeasureText(this.Text, this.Font, sz, TextFormatFlags.WordBreak);
          this.Height = sz.Height;
        }
        finally {
          mGrowing = false;
        }
      }
      protected override void OnTextChanged(EventArgs e) {
        base.OnTextChanged(e);
        resizeLabel();
      }
      protected override void OnFontChanged(EventArgs e) {
        base.OnFontChanged(e);
        resizeLabel();
      }
      protected override void OnSizeChanged(EventArgs e) {
        base.OnSizeChanged(e);
        resizeLabel();
      }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,393

    Re: How to text wrap with label in winforms

    You can give suitable size of label using a Graphics object and is MeasureString method:

    Code:
    using (System.Drawing.Graphics g = myLabel.CreateGraphics())
    {
    myLabel.Width = (int) g.MeasureString(myLabel.Text, myLabel.Font).Width + 10;
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to text wrap with label in winforms

    Did you look for the similar Threads made here. Everytime you make a thread you must first look for the similar threads... I have given you some links below for that similar threads. Now just have a look to find your solution there...

    In HTML table how can I wrap the text ?

    VBA code to wrap text?

Similar Threads

  1. Html need to know about text wrap padding around an image
    By ComPaCt in forum Software Development
    Replies: 2
    Last Post: 09-07-2009, 08:30 PM
  2. How to word wrap text in Powerpoint
    By jeffcoo in forum Windows Software
    Replies: 3
    Last Post: 12-06-2009, 12:06 PM
  3. VBA code to wrap text?
    By grouth in forum Microsoft Project
    Replies: 2
    Last Post: 23-09-2008, 07:30 PM
  4. Insert image in text box with word wrap
    By IpsA in forum MS Office Support
    Replies: 2
    Last Post: 25-05-2008, 01:07 PM
  5. In HTML table how can I wrap the text ?
    By Matellis in forum Software Development
    Replies: 5
    Last Post: 20-05-2008, 07:48 PM

Posting Permissions

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