104

I am trying to right align a control in a StatusStrip. How can I do that?

I don't see a property to set on ToolStripItem controls that specifies their physical alignment on the parent StatusStrip.

How do I get Messages drop down to be right aligned? http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90

Spongebob Comrade
  • 1,495
  • 2
  • 17
  • 32
Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202
  • 4
    Make a label toolbar item with Spring property set to true. Details: http://www.dotnetperls.com/statusstrip (P.S. Yes, I know that it's an old question.) – Nick Alexeev May 24 '11 at 21:29

8 Answers8

255

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.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202
  • 33
    This will work **ONLY** if `StatusStrip.LayoutStyle == ToolStripLayoutStyle.Table` (which is the default one) – AZ. Jul 31 '12 at 22:32
  • 15
    Nice. A StatusStripLabel with Spring on either side appears to center the controls – mcdon Oct 12 '12 at 14:23
  • 1
    I wish there was a "real" way of doing this, but this works so thanks. I wonder what the `Alignment` property does, because it didn't do anything in my application. – TheGateKeeper Jun 20 '14 at 16:27
  • 2
    _I wonder what the Alignment property does_ I don't see any such property. – TaW Oct 09 '16 at 09:48
  • 1
    This will only allow one item after the label with "Spring", the others will not appear, use @VBobCat method instead. – Pablo Carrasco Hernández Jun 22 '20 at 02:03
26

For me it took two simple steps:

  1. Set MyRightIntendedToolStripItem.Alignment to Right
  2. Set MyStatusStrip.LayoutStyle to HorizontalStackWithOverflow
VBobCat
  • 2,527
  • 4
  • 29
  • 56
5

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

Martijn Laarman
  • 13,476
  • 44
  • 63
4

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);
Celeo
  • 5,583
  • 8
  • 39
  • 41
Chandran R
  • 33
  • 3
  • _add a third middle cell and give this the fill property_ I don't see any such property. – TaW Oct 09 '16 at 09:51
2

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

Visakh V A
  • 320
  • 3
  • 19
2

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.

knightgambit
  • 166
  • 1
  • 7
1

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.

  • This answer is already given. When answering such an old question with a lot of answers, you need to check this before. – marsh-wiggle Aug 29 '20 at 13:15
-4

Set the RightToLeft tool strip property to True.