简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM