locked
Blank space in menu item RRS feed

  • Question

  • Hi,

     

    I just added a MenuStrip to a Windows Forms in my C# project (VS 2005). I changed the RenderMode property to System because the Professional value gives the menu a Office 2003 look that is not desired for my app.

    However, the space bewtween the left edge of the menu items (when displayed) and the start of the actual text is too big. This is not a problem when using the Professional render mode because that big, empty space is covered with a blue bar that makes it look so Office 2003. Buy in System mode, specially if the menu item does not have an image, then the emtpy space is too big and just looks bad.

     

    How can I get rid of such big space and have a menu look like a standard one (i.e like the menu in Notepad)?

     

    Since an image is worth a thousand words, I'll give you an ASCII image of the problem (I have a screenshot, but can't bother to upload it some web site), this is my "problem"

     

    File    Edit    Help

    |       Open    |

    |       Save     |

    |       Exit      |

    --------------------

     

    And this is what I want:

     

    File    Edit    Help

    |   Open    |

    |   Save     |

    |   Exit      |

    ----------------

     

    I have played with some ToolStripMenuItem (DisplayStyle = Text, TextImageRelation = Overlay) but I just can't get what I want. Thanks for any help!

    Thursday, August 14, 2008 10:10 PM

Answers

  • Try this:

      public partial class Form1 : Form {
        public Form1() {
          InitializeComponent();
          menuStrip1.Renderer = new MyRenderer();
        }
        private class MyRenderer : ToolStripSystemRenderer {
          protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
            int padding = 5;
            e.TextRectangle = new Rectangle(padding, e.TextRectangle.Top,
              e.TextRectangle.Right - padding, e.TextRectangle.Bottom);
            base.OnRenderItemText(e);
          }
        }
      }

    Friday, August 15, 2008 1:19 AM

All replies

  • Try this:

      public partial class Form1 : Form {
        public Form1() {
          InitializeComponent();
          menuStrip1.Renderer = new MyRenderer();
        }
        private class MyRenderer : ToolStripSystemRenderer {
          protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
            int padding = 5;
            e.TextRectangle = new Rectangle(padding, e.TextRectangle.Top,
              e.TextRectangle.Right - padding, e.TextRectangle.Bottom);
            base.OnRenderItemText(e);
          }
        }
      }

    Friday, August 15, 2008 1:19 AM
  • Hi,

     

    That code works fine, but in my opinion, the menu still doesn't look exactly the same as the old, classic menu style. The top-leve menus (File, Edit, Help) seem too padded (in all directions) and the space between the end of a menu item's text and the right edge of the menu area seems too big for my taste.

    In the end, I went back to the "Professional" rendering since at least it is consistent with the XP/Office 2003 look.

    At any rate, thanks for the help.

    Tuesday, August 19, 2008 6:38 PM