Hi,
Thanks for posting in this group.
If you want to adjust your label to fit all your text to display, the
simplest way is autosize property.
If you want to fix the label's length and cut the wapped text of label
control, you should use Graphics.MeasureString to determine the string's
length.
Sample code like this:
private void button1_Click(object sender, System.EventArgs e)
{
Graphics g=this.CreateGraphics();
Font f=label1.Font;
string labelstr=label1.Text;
char [] char_arr=labelstr.ToCharArray();
int width;
int count=0;
for(int i=0;i<char_arr.Length;i++)
{
width=(int)(g.MeasureString(labelstr.Substring(0,i +1),f).Width);
if(width>=label1.Width)
{
count=i;
break;
}
}
label1.Text=labelstr.Substring(0,count);
}
It works well on my machine.
Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.