I have a user control that has the following overridden event:
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Left )
DoSomething();
}
When I place the user control on my Main Form, this event is not fired.
How can I access this event from Parent form?
protected override void OnKeyDown(KeyEventArgs e)
{
e.Handled = true;
if (e.KeyCode == Keys.Left)
Move(pt.X,pt.Y);//Move is a function within the usercontrol
else if (e.KeyCode == Keys.Right)
Move(pt.X,pt.Y);
//other conditions
e.Handled = false;
}
I need the parent to be notified on this event
If I understand correctly, you are trying to invoke the
OnKeyDownmethod of the user control from within the parent form.This is the main form class:
And this is the User Control:
Edit regarding arrow keys: the arrow keys are not normally considered to be input keys and therefore are not passed on to the key methods. To change this you must override the
IsInputKeymethod as such: