Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to text wrap with label in winforms

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 14-07-2009
Member
 
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...??

Reply With Quote
  #2  
Old 14-07-2009
Member
 
Join Date: Apr 2008
Posts: 1,947
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();
  }
}
Reply With Quote
  #3  
Old 14-07-2009
Member
 
Join Date: May 2008
Posts: 2,382
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;
}
Reply With Quote
  #4  
Old 14-07-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
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?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 12:47 PM.