C#中按Esc键退出Form

论坛 期权论坛 脚本     
匿名技术用户   2021-1-5 15:25   518   0

1.在Load中设置keypreview设定为true

2.在KeyPress事件中定义关闭事件

//Load事件
private void Form1_Load(object sender, EventArgs e)
{
    this.KeyPreview = true;
}


//KeyPress事件
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Escape)
        {
            this.Close();
        }
}

原文:C#中按下esc 键, 退出 Form

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP