表单KeyPress事件工作 [英] Form KeyPress event working

查看:52
本文介绍了表单KeyPress事件工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单中有一个菜单栏.
当我按Alt + F7键时,显示另一种形式
怎么可能
请帮助我

在此先感谢

i have a menu strip in my form.
when i press the Alt+F7 key ,show another form
how it Possible
pls help me

thanks in advance

推荐答案

将ShortcutKeys属性设置为Alt + F7并编写以下代码:

set the ShortcutKeys property to Alt+F7 and write this:

private void yourToolStripMenuItem_Click(object sender, EventArgs e)
        {
           Form2 frm2 = new Form2();
            frm2.ShowDialog(); 

        }



希望对您有所帮助:)



hope it helps :)


我将使用KeyDown事件代替KeyPress.这是一个例子.

I would use KeyDown event instead of KeyPress. Here is an example.

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.F7)
    {
        MessageBox.Show("Hello!");
    }
}



当然,您会希望显示您的表单而不是MessagBox. :)



Of course instead of MessagBox you will want to show your form. :)


这篇关于表单KeyPress事件工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆