如何正确对齐 StatusStrip 中的控件?

我试图右对齐一个控制在一个 StatusStrip。我怎样才能做到这一点?

我没有在 ToolStripItem控件上看到要设置的属性,该属性指定它们在父 StatusStrip上的物理对齐方式。

如何使消息下拉到右对齐? http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90

72015 次浏览

Found it via MSDN forums almost immediately after posting :)

You can use a ToolStripLabel to pseudo right align controls by setting the Text property to string.Empty and setting the Spring property to true. This will cause it to fill all of the available space and push all the controls to the right of the ToolStripLabel over.

As an added note this is due to the fact that in the Win32 API a cell is either fixed width or fills the remaining space -1

int statwidths[] = {100, -1};


SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");

If memory serves me correctly you can have only one fill cell (-1) per statusbar.

You could also add a third middle cell and give this the fill property to get a more concistent looking StatusBar. Consistent because Messages has an inset to its left right where you'd expect it. A bit like the mspaint shot found on the MSDN page for StatusBars

I like the creative appreach though :D

You can display the Button at the end of the StatusStrip by using the logic below.

  1. Add a ToolstripLabel to the StatusStrip
  2. Set text as string.Empty
  3. Set Padding for the ToolstripLabel

For example:

this.toolStripStatusLabel1.Padding = new Padding((int)(this.Size.Width - 75), 0, 0, 0);

Set the RightToLeft tool strip property to True.

Keep a Toolstrip label , set Spring property as true and for label align text in BottomLeft

For me it took two simple steps:

  1. Set MyRightIntendedToolStripItem.Alignment to Right
  2. Set MyStatusStrip.LayoutStyle to HorizontalStackWithOverflow

I found that you can set the StatusStrip Layout to HorizontalStackWithOverflow. Then, for each control on the StatusStrip that you want on the right side, set the control Alignment to Right.

I like this better since you don't need any extra or dummy controls to align.

If you set a status strip label control’s Spring property to true, then that label takes up any space not used by other controls in the StatusStrip.