KeyUp processed for wrong control
<p>I have made a simple test application for the issue, two winforms each containing a button.
The button on the first form opens the other form when clicked. It also subscribes to keyup events.</p>

<p>The second form has its button set as "AcceptButton" and in the Clicked event we sleep for 1s and then set DialogResult to true (the sleep is to simulate some processing done)</p>

<p>When enter is used to close this second form the KeyUp event of the button on the first form is triggered, even though the key was released well before the second had passed so the second form was still shown and focused.</p>

<p>If any key other then enter is pressed in the second form the event is not triggered for the button on the first form.</p>

<p>First form:</p>

<pre><code>    public Form1()
    {
        InitializeComponent();
        buttonForm2.KeyUp += new KeyEventHandler(cntKeyUp);
    }

    void cntKeyUp(object sender, KeyEventArgs e)
    {
        MessageBox.Show(e.KeyCode.ToString());
    }

    private void buttonForm2_Click(object sender, EventArgs e)
    {
        using (Form2 f = new Form2())
        {
            f.ShowDialog();
        }
    }
</code></pre>

<p>Second form:</p>

<pre><code>    private void button1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(1000);
        this.DialogResult = DialogResult.OK;
    }
</code></pre>

<p>Does anyone know why the event is triggered for the button on the non active form and what can be done to stop this from happening?</p>
