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.Measur eString to determine the string's
length.
Sample code like this:
private void button1_Click(o bject sender, System.EventArg s e)
{
Graphics g=this.CreateGr aphics();
Font f=label1.Font;
string labelstr=label1 .Text;
char [] char_arr=labels tr.ToCharArray( );
int width;
int count=0;
for(int i=0;i<char_arr. Length;i++)
{
width=(int)(g.M easureString(la belstr.Substrin g(0,i+1),f).Wid th);
if(width>=label 1.Width)
{
count=i;
break;
}
}
label1.Text=lab elstr.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.