Home > Net >  How to position two ToolStripStatusLabel to different sides of StatusStrip
How to position two ToolStripStatusLabel to different sides of StatusStrip

Time:04-24

I am using .NET 6.0 with VS2022 IDE. How to place 2 toolStripStatusLabel1 at two corners of status strip control. I am not able to make any grouping. So please share some suggestions if it is possible.

this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(151, 20);
this.toolStripStatusLabel1.Text = "SUM Count Average";
// 
// toolStripStatusLabel2
// 
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
this.toolStripStatusLabel2.Padding = new System.Windows.Forms.Padding(1000, 0, 0, 0);
this.toolStripStatusLabel2.Size = new System.Drawing.Size(1151, 20);
this.toolStripStatusLabel2.Text = "Elaped Time";

CodePudding user response:

You can use either or the following solutions to set different alignment for the items of StatusStrip:

  • Set LayoutStyle to HorizontalStackWithOverflow
  • OR Use Spring property of a label to control the flow.
  • OR use a ToolStrip instead.

Option 1: Set LayoutStyle to HorizontalStackWithOverflow

Setting alignment for the items of StatusStrip doesn't work when the LayoutStyle is Table. That's because of the custom logic that it has to support Spring property. To solve the issue:

Set the LayoutStyle property of the StatusStrip to HorizontalStackWithOverflow, then the Alignment of the desired ToolStripStatusLabel to the Right in code (because the Alignment property of ToolStripStatusLabel is hidden in design-time).

Note: Keep in mind that by changing the layout style, setting Sprint has no more effect.


Option 2: Use Spring property of a label to control the flow

You can use 3 ToolStripStatusLabel items; Then for the middle one, set the Text to empty and set the Spring to true to fill the space. Then the items before the items before this one will be aligned to the left and items after, will be aligned to the right.


Option 3: Use a ToolStrip instead

Instead of StatusStrip, use a ToolStrip and add 2 ToolStripLabel, and for the second one, set the Alignment to Right.

Note: The main UX difference is missing the size grip.

  • Related