文字过长时,StatusStrip标签不可见 [英] StatusStrip label not visible when text too long
问题描述
我有一个StatusStrip
停靠在C#窗体的底部,它包含一个标签,其中的文本显示正常,除非当文本的长度较长时,它根本不会显示,我必须扩大表格,然后突然出现.是否可以将其显示为以下形式:
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.
推荐答案
您可以基于 OnRenderItemText
方法并用省略号绘制文本:
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);
}
}
然后设置 Renderer
:
Then it's enough to set Renderer
of your StatusStrip
to your custom renderer:
this.statusStrip1.Renderer = new CustomRenderer();
在下面的示例中,您可以看到ToolStripStatusLabel
的行为,它是
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
:
这篇关于文字过长时,StatusStrip标签不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!