Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set WordWrap = false for a Label

Tags:

.net

winforms

How should I set WordWrap = false to a System.Windows.Forms.Label?

I have a header on a panel, and it should show "MyPanel capt...". So I use AutoEllipsis = true, but it is not sufficient.

I also use "AutoSize = true", because I want that the label takes the minimum space possible.

Apropos, Visual Basic 6.0 did it.

like image 994
serhio Avatar asked Apr 13 '10 14:04

serhio


2 Answers

I've got a similar effect working using:

label1.AutoSize = false;
label1.AutoEllipsis = true;

and sizing the label area to be one line in height only.

like image 122
Neil Moss Avatar answered Nov 23 '22 18:11

Neil Moss


I'm pretty sure you can't prevent labels from wrapping. An alternate (if slightly crude) option is to set the label to auto-size (so the width grows with the text), and then put a Control next to it that sits in front of it in the z-order. That way, when the label width goes past a certain point the content of the label overlap will be hidden by that other control.

Like I said, it is a pretty crude method of achieving the effect.

Also, if you are trying to use AutoEllipsis, i'm assuming you've disabled AutoResize? I believe it takes precedence.

like image 35
Alistair Evans Avatar answered Nov 23 '22 17:11

Alistair Evans