Showdialog causes unwanted behavior

I have a form in my application that, by clicking the help button, opens the help form using the show () function. when I open another dialog from the same main form using showDialog (), the help form is disabled. Do you have ideas? I don't want to open a dialog with show () ....

+2


source to share


2 answers


The whole point ShowDialog

is that it opens it in a modal way, i.e. blocks existing forms. If you don't want this behavior, then don't use ShowDialog

. Why don't you want to use the modeless method Show

?



EDIT: If you just want to "disable" one form, I suspect you will need to run that form on a different UI thread. I think the modal dialog affects all other forms on the same UI thread, which is called ShowDialog

. (Eventually ShowDialog

blocks this UI thread.)

+8


source


An easy way to accomplish what you want is to open a second dialog using the Show overload, which takes the main form as an owner parameter and simultaneously disables the main form, for example:

frmDialog myDialog = new frmDialog();
frmDialog.Show(this);
this.Enabled = false;

      

Then, in the FormClosing event of the dialog box (frmDialog), you re-enable the main form like this:



this.Owner.Enabled = true;

      

This will cause the dialog to act as if it had been opened with ShowDialog (), leaving your help form enabled and available.

+3


source







All Articles