0
Answer

UserControl Keydown Event Not Fire Against Revoke Windows Application KeyDown Event

Ask a question

I have UserControl and facing problem of KeyDown Event. My UserControls will shows against revoke of windows forms keydown event like below:

User Control's Event:

private void UserControl_KeyDown(object sender,KeyEventArgs e)
{
        if ((Keys)e.KeyCode == Keys.Escape) 
        {
            this.Visible = false;

        }

}

The above event will have to hide the UserControl but the event not fire due to revoke of windows forms keydown as below:

Windows Form:

private void button1_Click(object sender, EventArgs e)
{
        panel1.SendToBack();
        panel2.SendToBack();
        panel3.SendToBack();
        panel4.SendToBack();
        am.Focus();
        this.KeyDown -= new KeyEventHandler(Form1_KeyDown);

}

This will shows the UserControls as the UserControls are added to windows forms by as below:

    private UserControl.UserControl am = new UserControl.UserControl();
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(am);

    }

I want to revoke the keydown event of winform against visible of UserControl and fire the keydown event of UserControl for hide the UserControl but it's not doing well. The keydown event of UserControl event is not fire. Don't know why?. How to do the same in proper way?.