Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C# Menu Control



A Menu on a Windows Form is created with a MainMenu object, which is a collection of MenuItem objects. MainMenu is the container for the Menu structure of the form and menus are made of MenuItem objects that represent individual parts of a menu.

You can add menus to Windows Forms at design time by adding the MainMenu component and then appending menu items to it using the Menu Designer.

After dragging the Menustrip on your form, you can directly create the menu items by type a value into the “Type Here” box on the menubar part of your form. From the following picture, you can understand how to create each menu items on the main menu Object.

If you need a separator bar, right-click on your Menu then go to insert->Seperator.

After creating the Menu on the form, you have to double click on each menu item and write the programs there depends on your requirements. The following C# program shows how to show a message box when clicking a menu item.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void menu1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You are selected MenuItem_1");
        }
    }
}

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More