Hey guys, I want that when I press the F2 button on the textbox, a new form shows up. I have KeyPreview setted to true, and I am using a KeyDown event, here is the code:

 private void txtnumero_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2) {

                fmrplantnum sfpn = new fmrplantnum();

                sfpn.Show();

            }

        }

It doesn't works...

Recommended Answers

All 2 Replies

You do realize that the form will only exist for a fraction of a second as the form goes out of scope immediatly after you show it.

Maybe, tou need to define fmrplantnum sfpn; at form level, then on the txtnumero_KeyDown use

 sfpn = new fmrplantnum();
 sfpn.Show();

This will not destroy the frmplantum immediately after showing.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.