|
| ||||||||||
| Tags: label, text, winforms, wrap |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to text wrap with label in winforms
|
|
#2
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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? |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to text wrap with label in winforms" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to word wrap text in Powerpoint | jeffcoo | Windows Software | 3 | 12-06-2009 12:06 PM |
| How to Wrap Text in Cells of Excel 2007 | Leonard | Windows Software | 3 | 25-04-2009 10:27 AM |
| 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 |