简体   繁体   English

由于按钮 Visual Studio 2013,Form 上的 PressKey 确实有效

[英]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.

相关问题 GeckoFX在Visual Studio 2013上不起作用 - GeckoFX does not work on visual studio 2013 将Metro控件拖放到Windows窗体在Visual Studio 2013中不起作用 - drag and drop metro control to windows form does not work in visual studio 2013 使用Visual Studio 2013使用SQLITE数据库 - Work with SQLITE database using visual studio 2013 在visual studio express 2013中“拖放形成”计时器不起作用 - “drag and drop to form” timer in visual studio express 2013 doesn't work Visual Studio .NET Windows 窗体项目在部署后不起作用 - Visual Studio .NET Windows Form Project does not work after deployment Visual Studio 2013编码的UI无法识别单选按钮 - Visual Studio 2013 Coded UI failing to recognise Radio buttons 脚手架控制器不适用于Visual Studio 2013更新3和4 - Scaffolding controller doesn't work with visual studio 2013 update 3 and 4 “没有可用于'C:\\ Users \\…\\ Form1.cs'的编辑器。”(Visual Studio 2013) - “There is no editor available for 'C:\Users\…\Form1.cs'.” (Visual Studio 2013) 让Monogame内容管道在Windows 8中与Visual Studio 2013一起使用 - Getting Monogame content pipeline to work with Visual studio 2013 in windows 8 Visual Studio 2013 Excel VSTO将WPF或Windows窗体添加到文档 - Visual Studio 2013 Excel VSTO Add WPF Or Windows Form To Document
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM