Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Adding fill to the right in a ToolStrip

    I have a tool strip that contains a few controls, but not enough to fill all of the horizontal space available. I'd like the controls to be left justified in the strip and then have the strip background continue to the right to fill the remaining space.

    I've tried ToolStrip.addFill() followed by ToolStrip.addFormItem(new SpacerItem()). That just results in a little extra background to the right, but it doesn't fill the available horizontal space. If I setWidth100() on the strip the controls are spaced out evenly to fill the available space, which is still not what I'm after.

    How to I add a filler so that the controls remain left justified but the strip still fills 100% of the width.

    #2
    You want setWidth100(), but you also want to change the horizontal layoutPolicy to "none" to prevent the ToolStrip from trying to widen controls to fill available space.

    Comment


      #3
      I tried that too. I think the problem is with the FormItems that I'm adding to the strip (a series of buttons). The rest of the controls are left justified but the ButtonItems are "justified" in the remaining space. I've attached a screenshot.
      Attached Files

      Comment


        #4
        Changing the layoutPolicy should correct this.

        However, why are you using ButtonItems for this instead of the dedicated ToolStripButton class (which has a more ToolStrip-like appearance)?

        Comment


          #5
          No good reason except the ButtonItems were already there and I'm switching from using a form to a toolstrip. I've changed them to ToolStripButttons and, not only do they look better, the are left justified now.

          Comment

          Working...
          X