Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StatusStrip label not visible when text too long

I have a StatusStrip docked to the bottom of a C# Form, it contains a label, the text in it displays fine, except when there is longer length of text then it does not display at all, and I have to widen the form and then all of a sudden it appears. Is it possible to show it in the form below:

    This is a very long tex...

So that the user knows that the app is showing something and then he can widen it himself, because when it is not visible at all, it does not indicate anything to user.

like image 371
Ahmed Avatar asked Jul 02 '16 00:07

Ahmed


3 Answers

You can create a custom renderer based on ToolStripProfessionalRenderer and override OnRenderItemText method and draw text with ellipsis:

public class CustomRenderer : ToolStripProfessionalRenderer
{
    protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
    {
        if (e.Item is ToolStripStatusLabel)
            TextRenderer.DrawText(e.Graphics, e.Text, e.TextFont,
                e.TextRectangle, e.TextColor, Color.Transparent,
                e.TextFormat | TextFormatFlags.EndEllipsis);
        else
            base.OnRenderItemText(e);
    }
}

Then it's enough to set Renderer of your StatusStrip to your custom renderer:

this.statusStrip1.Renderer = new CustomRenderer();

In below example, You can see the behavior of a ToolStripStatusLabel which it's Spring property is set to true and its StatusStrip uses CustomRenderer:

enter image description here

like image 66
Reza Aghaei Avatar answered Nov 18 '22 18:11

Reza Aghaei


If you set

ToolStripStatusLabel.Spring = True;

then you won't get the "..." but the text will be shown even when the available space is insufficient.

like image 43
Ronny D'Hoore Avatar answered Nov 18 '22 18:11

Ronny D'Hoore


On Visual Studio 2017, the accepted answer didn't work for me. So here is another simple solution. Set LayoutStyle property of StatusStrip to Flow. i.e:

 statusStrip1.LayoutStyle= LayoutStyle.Flow;

And Set

`statusStrip1.AutoSize= false;`
like image 3
HN Learner Avatar answered Nov 18 '22 20:11

HN Learner