[英]PressKey on Form does work because of buttons Visual Studio 2013
I have the following problem.我有以下问题。 I have a school project on visual studio 2013 and i want to open the Menu Form by pressing any key on the keyboard.
我在 Visual Studio 2013 上有一个学校项目,我想通过按键盘上的任意键打开菜单表单。 I have the following code so far.
到目前为止,我有以下代码。
public partial class START : Form
{
public START()
{
InitializeComponent();
this.KeyPress += new KeyPressEventHandler(START_KeyPress);
}
void START_KeyPress(object sender, KeyPressEventArgs e)
{
Meniu form2 = new Meniu();
form2.Show();
this.Hide();
}
The problem is this doesn t work when i have some buttons on the Form as well.I think it s has to be something with the form focus, but im not sure.问题是当我在表单上也有一些按钮时这不起作用。我认为它必须与表单焦点有关,但我不确定。 If anyone could help me, I'd be very gratefull.
如果有人可以帮助我,我将非常感激。
The code works.该代码有效。 You just have to activate the The KeyPreview property.
您只需激活 KeyPreview 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.