DucAnhNguyen
DucAnhNguyen

Reputation: 71

Can't fire event Key_Down c#

I using form event Form1_KeyDown to move panelcontrol4

Private void Form1_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.Left)
     {
        panelControl4.Location = new Point(panelControl4.Location.X-1,panelControl4.Location.Y);
     }
}

If Form1 have 1 control panelcontrol4 event worked but i add 1 control eg : simplebutton1 ... then can't fire Form1_KeyDown . Then i must enable = false simplebutton1 , then Form1_KeyDown work

Thanks you for help

enter image description here

enter image description here

Upvotes: 0

Views: 95

Answers (3)

DucAnhNguyen
DucAnhNguyen

Reputation: 71

I solve my problem , i must overide event KeyDown and PreviewKeyDown @Matthew Watson

Upvotes: 0

sujith karivelil
sujith karivelil

Reputation: 29006

In General The _KeyDown will Occurs when a key is pressed while the control has focus. In your case the Form1 doesn't have Focus at the Time of key press occurs.

Upvotes: 1

Eli
Eli

Reputation: 693

Controls on your form might automatically handle the keydown event and your code won't get called. See Control.KeyDown Event.

Upvotes: 1

Related Questions