ShowDialog() from within a ShowDialog() - both closing

I hit this really weird behavior with Win Forms dialog boxes just now.

Try opening a Dialog Box inside another DialogBox in .NET (1.1 or 2.0) and setting the DialogResult on the second form to be one of the results (OK, Cancel etc). The second dialog box will close, but the first dialog box will also close.

For example, say you have a dialog with two buttons. Button1 opens a new instance of the dialog, and Button2 closes its parent form (the form on which it exists) by setting DialogResult to be DialogResult.OK:

class MyDialog : Form
{
private void Button1_Click(object sender, EventArgs e)
{
new MyDialog().ShowDialog(this);
}

private void Button2_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
}

If the user clicks Button1 multiple times and then hits Button2 just once, all the dialog boxes will be closed one after another.

To solve this problem, you need to reset the DialogResult to None after you call a dialog box from another dialog box:

   private void Button1_Click(object sender, EventArgs e)
{
new MyDialog().ShowDialog(this);
DialogResult = DialogResult.None;
}

Not sure for the reason behind this behavior, but there it is... I was stumped there for a few minutes.

Edit: BTW - this only reproes if you set the AcceptButton and CancelButton properties on the form to point to the buttons you created. Apparently that's the trigger that manifests the bug.