Using StatusStrip in C#
Asked Answered
P

5

13

Consider System.Windows.Forms.StatusStrip. I have added a StatusStrip to my Windows Forms application, but I am having a few problems.

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.

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.

Potful answered 14/1, 2009 at 18:1 Comment(0)
B
29

Just set the Spring property on the label control to True and you should be good to go.

Burglarize answered 14/1, 2009 at 18:19 Comment(1)
If you do that you'd also want to change the label's default alignment from MiddleCenter to LeftCenter.Bolus
B
6

What you have to do is set the alignment property of your progressbar to right. Then set the LayoutStyle of the StatusStrip to 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;
Bolus answered 14/1, 2009 at 18:21 Comment(3)
Please, God - there's got to be a way to set that up visually. :)Sideline
There is. I was showing the designer code. Just find the properties in the property panel...Bolus
Actually the Alignment property is not available in the property grid of the ToolStripStatusLabel class (for some reason it has the Browsable(false) attribute, at least in .NET 4).Dishonesty
L
2

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.

Lithography answered 14/1, 2009 at 18:23 Comment(1)
Thanks - this is the correct answer if you want more than one right-aligned label. No idea why this would have got marked down.Aleutian
S
0

Did you tried the Alignment property of ProgresBarToolStripItem set to the Right?

Septime answered 14/1, 2009 at 18:19 Comment(0)
D
0

Open your Designer and set this.toolStripStatusLabel1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;

Dramamine answered 19/11, 2010 at 4:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.