Set WordWrap = false for the label

How to install WordWrap = falseon System.Windows.Forms.Label?

I have a title in the panel and it should show "MyPanel capt...". Therefore, I use AutoEllipsis = true, but this is not enough.

I also use " AutoSize = true" because I want the label to take up minimal space.

Apropos, Visual Basic 6.0 did this.

+3
source share
7 answers

I found a solution:

this.label.AutoEllipsis = true;
this.label.AutoSize = true;

In the event handler to resize:

...
textHeight = this.label.Font.SizeInPoints; // Take in pixels, not points
...
Size newMaxSize = new Size(this.Width,
    textHeight + label.Padding.Top + label.Padding.Bottom);
this.label.MaximumSize = newMaxSize;
...
+1
source

I have a similar effect using:

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

and calibrate the label area with just one line.

+3
source

, . ( ) , ( ), , z-. , , .

, .

, AutoEllipsis, , AutoResize? , .

+1

MaximumSize.

+1

, - . , Text - .

, , CRLF Text - .

0

, , , .

, AutoSize . AutoEllipsis. ?

, MaximumSize, AutoEllipsis AutoSize. . , . .

0

I use FlowLayoutPanel to store shortcuts from left to right. Thus, automation and overlap break my well-aligned columns. I think the most direct way is to simply implement the paint yourself. Helpers exist to make an ellipse for you.

This latest TextFormatFlags has a dozen options that save you unnecessary drawing code.

    private void templateLabel_Paint(object sender, PaintEventArgs e)
    {
        Label lbl = sender as Label;
        e.Graphics.Clear(lbl.BackColor);

        TextRenderer.DrawText(e.Graphics, lbl.Text, lbl.Font,
            lbl.ClientRectangle,
            Color.Black,
            lbl.BackColor, TextFormatFlags.EndEllipsis);
    }
0
source

Source: https://habr.com/ru/post/1740935/


All Articles