2

I want to put a gap between menustrip and form at right of menuStrip. I used autosize= false and new size properties, height of menustrip is changed but width is not changed. Menustrip's width remain same with form's width.

menuStrip2.AutoSize = false;
menuStrip2.Size = new Size(50, 90); 

I can not change from Desing-> Properties -> Size, too.

I only create a gap from menustrip's right to form's left.

leppie
  • 115,091
  • 17
  • 196
  • 297
Anil Kocabiyik
  • 1,178
  • 6
  • 17
  • 47
  • http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripprofessionalrenderer.aspx should give you a good idea of how / when to access items. – Paul Zahra Apr 16 '13 at 08:08
  • And take a look at how to correctly use size... http://msdn.microsoft.com/en-us/library/system.windows.forms.control.size.aspx It looks as though perhaps you need to set the size of the buttons, the buttons are probably larger than you are setting the menustrip and the menu strip is resized automatically to accomodate, just like a DIV acts. – Paul Zahra Apr 16 '13 at 08:10
  • Just set the Dock property to None. Probably add the right anchor, can't really understand menustrip's right vs form's left. – Hans Passant Apr 16 '13 at 11:30

2 Answers2

5

Here's how you do this at design-time:

  1. Create a new form.

  2. place two panels on this form. Call them panelTop and panelFill. Set there dock properties to Top and Fill respectively. Resize panelTop to the height you want you menu strip to be.

  3. Add another panel to panelTop, call it panelTopRight. Dock this panel Right.

  4. Add your menu strip. Set the dock property to fill.

  5. Right click on panelTopRight and 'Send to Back'. Now you can resize the panelTopRight to allow the gap that you require.

If you want to do this at run-time you will have to perform all of the above in code; but that is perhaps another question...

I hope this helps.

MoonKnight
  • 23,214
  • 40
  • 145
  • 277
  • 1
    Killercam..! Isn't it better to use ToolStripContainer instead. We may resize the container then. – Khadim Ali Apr 16 '13 at 08:26
  • 1
    You can do what the OP wants with a `ToolStripContainer`. He wants a menu at the top and did not mention being able to reposition the strip - in which case this is the best and simplest way to go... Plus, with the above you are still free to resize the menu ass you wish, the menu is bound to the height of `panelTop`. – MoonKnight Apr 16 '13 at 08:30
  • *You can't do what the OP wants with a `ToolStripContainer`. – MoonKnight Apr 16 '13 at 11:36
0

Open xyz.designer.cs file, then look for Windows Form Designer generated code after that see for events generated for menustrip items then,

this.menuStripnameToolStripMenuItem.Padding = new System.Windows.Forms.Padding(4, 0, 81, 4);

  • Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone Jun 12 '15 at 07:22