在 C# 中使用 StatusStrip
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/444031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using StatusStrip in C#
提问by Brad
Consider System.Windows.Forms.StatusStrip. I have added a StatusStrip to my Windows Forms application, but I am having a few problems.
考虑System.Windows.Forms.StatusStrip。我已将 StatusStrip 添加到我的 Windows 窗体应用程序中,但我遇到了一些问题。
I would like to have a label anchored at the left and a progressbar anchored on the right in the StatusStrip, but I can't find a way to set these properties.
我希望在 StatusStrip 的左侧有一个标签,在右侧有一个进度条,但我找不到设置这些属性的方法。
I then thought that I may need to create two StatusStrips and anchor them on either side of the bottom of the form... That didn't pan out; besides that, it just doesn't feel right.
然后我想我可能需要创建两个 StatusStrips 并将它们锚定在表单底部的两侧......这并没有成功;除此之外,就是感觉不太对劲。
采纳答案by Sean Bright
Just set the Spring
property on the label control to True
and you should be good to go.
只需将Spring
标签控件上的属性设置为True
,您就可以开始使用了。
回答by TcKs
回答by Steven Behnke
What you have to do is set the alignment property of your progressbar to right. Then set the LayoutStyle of the StatusStrip to HorizontalStackWithOverflow.
您需要做的是将进度条的对齐属性设置为正确。然后将 StatusStrip 的 LayoutStyle 设置为 HorizontalStackWithOverflow。
private void InitializeComponent()
{
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1,
this.toolStripProgressBar1});
this.statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
this.statusStrip1.Location = new System.Drawing.Point(0, 250);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(467, 22);
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(117, 17);
this.toolStripStatusLabel1.Text = "toolStripStatusLabel1";
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16);
}
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
回答by dr.manhattan
This can be achieved with the default table layout for the statusStrip by simply putting another label between your current label and your progressBar and set the Spring property to true.
这可以通过 statusStrip 的默认表格布局来实现,只需在当前标签和 progressBar 之间放置另一个标签,并将 Spring 属性设置为 true。
回答by anbu
Open your Designer and set this.toolStripStatusLabel1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
打开您的设计器并设置 this.toolStripStatusLabel1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;