在C#中使用StatusStrip

时间:2009-01-14 18:01:10

标签: c# winforms anchor statusstrip

考虑System.Windows.Forms.StatusStrip。我已经将StatusStrip添加到我的Windows窗体应用程序中,但是我遇到了一些问题。

我想在左边有一个标签,在StatusStrip的右边有一个进度条,但我找不到设置这些属性的方法。

然后我想我可能需要创建两个StatusStrips并将它们锚定在表单底部的任何一侧......这样就没有了;除此之外,它感觉不对。

5 个答案:

答案 0 :(得分:29)

只需将标签控件上的Spring属性设置为True,您就应该好了。

答案 1 :(得分:7)

您需要做的是将进度条的对齐属性设置为右侧。然后将StatusStrip的LayoutStyle设置为Horizo​​ntalStackWithOverflow。

    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;

答案 2 :(得分:2)

这可以通过statusStrip的默认表格布局来实现,只需在当前标签和progressBar之间添加另一个标签,并将Spring属性设置为true。

答案 3 :(得分:0)

您是否尝试将ProgresBarToolStripItem的Alignment属性设置为Right

答案 4 :(得分:0)

打开您的Designer并进行设置 this.toolStripStatusLabel1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;