[转]C#WinForm应用程序——添加菜单栏MenuStrip

【C#WinForm应用程序——添加菜单栏MenuStrip】

2018年08月09日 10:53:07 咸鱼不会游泳 阅读数:1360

1. 拖动MenuStrip到设计窗口

这里写图片描述

2. 编辑弹出和退出两个菜单,设置快捷键需要在前面加&

这里写图片描述 
这里写图片描述

3. 给弹出和退出添加事件代码

分别双击弹出和退出(E),更改的代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void 弹出ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            MessageBox.Show("我是“弹出”菜单");
        }

        private void 退出EToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            MessageBox.Show("我点击了“退出”菜单,确认后程序将关闭");
            Application.Exit();
        }
    }
}

4. 运行结果

这里写图片描述 
这里写图片描述

添加状态栏和工具栏可以举一反三类似这样的操作

猜你喜欢

转载自blog.csdn.net/cxu123321/article/details/85637246