I have some trouble showing a disabled Form in non-modal state. Here is the example code:
public partial class Form1 : Form
{
// ....
private void button1_Click(object sender, EventArgs e)
{
try
{
Form2 form = new Form2();
form.Enabled = false;
form.Show(); // works, but form has no owner
// form.Show(this); // gives an System.InvalidOperationException
// ...
// ... my program here shows a message box, ask user for something
// ... while 'form' is shown in the background
form.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Any idea why Show()
(without parameter) works, but Show(this)
gives an exception? In my scenario, form
must know its owner to be shown correctly, so I can do the following:
form.Enabled = false;
form.Owner=this;
form.Show();
but is this really a good solution?
EDIT: Thanks for the quick answers. Seems that we really found a bug in the framework here. In spite of your suggestions, I think I will keep with my solution, since disabling the form after the 'Show' gives an ugly visible effect to the user.