Save dialog will open when Save menu item clicked. private void saveToolStripMenuItem_Click_1( object sender, EventArgs e) Write code on the Click event of the Save submenu item. Open dialog will open when Open menu item clicked. OpenFileDialog fld = new OpenFileDialog() private void openToolStripMenuItem_Click( object sender, EventArgs e) Write code on the Click event of the Open submenu item. New child Form will open when New menu item clicked. Private void newToolStripMenuItem_Click(object sender, EventArgs e) Write code on the Click event of the New submenu item. Private void frmMenuStrip_Load(object sender, EventArgs e) Private void exitToolStripMenuItem_Click_1( object sender, EventArgs e) Private void saveToolStripMenuItem_Click_1( object sender, EventArgs e) Private void openToolStripMenuItem_Click( object sender, EventArgs e) private void newToolStripMenuItem_Click( object sender, EventArgs e) Insert text in the MenuStrip which you want to display as the menu.Ĭreate event handlers for the above menu items as New, Open, Save, Exit on the MenuStrip and selecting submenu items then double click on them. NET 3.5 and 4.0, the MainMenu control is replaced with the MenuStrip control.ĭrag and drop MenuStrip control from the toolbox on the window Form.įor creating a menu simply add a menu item in the shown textbox. NET 1.0 and 2.0, you must be familiar with the MainMenu control. This might be useful for others.Where the MenuStrip class is the foundation of menus functionality in Windows Forms. ((ToolStripMenuItem)menuStrip.Items).DropDownItems.Add(newItem) ("i" is the menu button index you want to add sub-entries) ToolStripMenuItem newItem = new ToolStripMenuItem("Button Name", null, ToolStripMenuItem_Click)īackColor = toolStripMenuItem01.BackColor,įoreColor = toolStripMenuItem01.ForeColor, You can use constant or different values. The color, size and other properties are just used this way for testing. Here you can manipulate (for example: add) the elements of the drop-down menu. ToolStripMenuItem TSMI = new ToolStripMenuItem("Button name") Renderer = new ToolStripProfessionalRenderer(new submenuColorTable()), Get Ģ.- Using it on MenuStrip: menuStrip.Renderer = new ToolStripProfessionalRenderer(new LeftMenuColorTable()) ģ.- Adding ContextMenuStrip to the menu element programmatically ContextMenuStrip CMS = new ContextMenuStrip() Through the function, you can easily manipulate the sub-elements that appears as drop-down elements.ġ.- The color tables: public class submenuColorTable : ProfessionalColorTable.ToolStripMenuItems on your MenuStrip must has a ContextMenuStrip as DropDown.Ohh, yes: The beauty in this is that you don't need to use any special components. It is easy to add any MenuStrip a ContextMenuStrip as a DropDown menu. Then I turend out by myself that ContextMenuStip has the properties to achieve the goals. Then I found how MenuStrip can be customized quiet easily in Stackoverflow forums, however I still got the issue with the dropdowns. I not only had the problem with the hover of the dropdown menu elements, but the background and overally the layout and how could I add sub-elements programmatically. I had the similar question and I went through many articles, many forums, but have not found the perfect answer for my questions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |