469,645 Members | 1,174 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

How to prevent Label text from wrapping?

abc
This seems like a stupid question, but I can't find the property to prevent
the text in a Label control from wrapping on the next line. Thanks.
Nov 15 '05 #1
4 9190
Try with setting 'AutoSize' property to true.

Thanks,
VijayaKrishna P.
"abc" <ab*@xyz.com> wrote in message
news:#B**************@TK2MSFTNGP09.phx.gbl...
This seems like a stupid question, but I can't find the property to prevent the text in a Label control from wrapping on the next line. Thanks.

Nov 15 '05 #2
Hi,

Make the height of the label lower, just the height of a line, in this case
you will not see the rest of the text. or use AutoSize as pondala suggested.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"abc" <ab*@xyz.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
This seems like a stupid question, but I can't find the property to prevent the text in a Label control from wrapping on the next line. Thanks.

Nov 15 '05 #3

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.

Nov 15 '05 #4

Hi,

Does our posts make sense to you?
If you still have any concern, please feel free to tell me.

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.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Baro | last post: by
4 posts views Thread by Richard MSL | last post: by
5 posts views Thread by le_mo_mo | last post: by
1 post views Thread by mg | last post: by
2 posts views Thread by David | last post: by
14 posts views Thread by Ed Jay | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.