Views: 112 visits

C# (C#) programming training, we will teach MenuStrip in C# (C#) in order to create a menu (menu) in your C# project, you need to use MenuStrip. Stay with us to learn how to use and implement. Learn MenuStrip tutorial in C#.

Like all C# objects, we can create MenuStrip or menu by using code and also by using drag and drop.
Well, in order to come through the ui, create a menu similar to the one below, just follow the pictures below.

Drag and drop the MenuStrip onto the form.
After that, you can create your own menus in the Type Here section, just type in it.

We implemented something like this.

To create a click event, just double-click on each one and write the code in the opened event.
Let’s go to create a menu using code.

MenuStrip MainMenu = new MenuStrip();
MainMenu.BackColor = Color.OrangeRed;
MainMenu.ForeColor = Color.Black;
MainMenu.Text = "File Menu";
MainMenu.Font = new Font("Georgia", 16);

Above, the MenuStrip object is created, then the background color and text are determined, as well as the font.
The Text feature is used to determine the text of the menu.
Use the following code to determine whether Menu is left-aligned or right-aligned.

MainMenu.Dock = DockStyle.Left;

To create Menu Items, you must use the following code.

ToolStripMenuItem FileMenu = new ToolStripMenuItem("File");
FileMenu.BackColor = Color.OrangeRed;
FileMenu.ForeColor = Color.Black;
FileMenu.Text = "File Menu";
FileMenu.Font = new Font("Georgia", 16);
FileMenu.TextAlign = ContentAlignment.BottomRight;
FileMenu.ToolTipText = "Click Me";
MainMenu.Items.Add(FileMenu);

Above, we have added an item to the first option, namely File, and some features have been used to determine the color of the text and background, as well as the font.
To define the click event on the Menu, just use the following Event.

FileMenu.Click += new System.EventHandler(this.FileMenuItemClick);
private void FileMenuItemClick(object sender, EventArgs e)
{
    MessageBox.Show("File menu item clicked");
}

be successful and victorious.

 

ادامه مطلب