8

Is it possible to add a lable/toostriplabel to a menustrip in a c# winform? I can't find an option to add it dierctly.

I want to add something that describes the status of a program, but I don't want to use a status bar for space.

Jerry
  • 4,258
  • 3
  • 31
  • 58
  • You should be able to add a [System.Windows.Forms.ToolStripLabel](http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstriplabel.aspx). I think it's not shown at design time because the MenuStrip isn't meant to have labels, it's meant to have MenuItems... normally when you want labels you use a regular ToolStrip. – Trevor Elliott Oct 16 '13 at 17:28
  • 5
    You can copy and paste a ToolStripLabel in the designer or add it in code. But Microsoft thinks you shouldn't. Because menus aren't supposed to have labels. – Trevor Elliott Oct 16 '13 at 17:31

1 Answers1

12

Simply ToolStripLabel is just a ToolStripItem and MenuStrip.Items is a collection of ToolStripItem so you can just add a ToolStripLabel to MenuStrip normally like this:

menuStrip1.Items.Add(new ToolStripLabel("Status"));

To control the distance between the ToolStripLabel and the Left-side ToolStripItem, you can set the Margin property of your ToolStripLabel, like this:

toolStripLabel1.Margin = new Padding(50,3,3,3);
King King
  • 61,710
  • 16
  • 105
  • 130
  • Thanks! this is working. But I think it's easier to copy and paste it as Trevor suggested – Jerry Oct 16 '13 at 17:42
  • 2
    @Jerry I misunderstood your question, if you mean `Drag-n-drop or add ToolStripLabel at design time` (which is a better description than `directly`), I think `copying-n-pasting` looks like the easiest solution. However I don't even understand what `Trevor` said, it's not really clear although I understand how to do the `Copy-n-paste`, first we have to drag-n-drop some `ToolStrip`, add some `ToolStripLabel` to that `ToolStrip` by the designer and then just Copy and Paste. – King King Oct 16 '13 at 17:54