Temporarily hide modal dialog

I have a modal dialog displayed with the main application window set as the owner (as in dialog.ShowDialog(mainAppWindow)), and I would like to temporarily allow the user to interact with the main application window before returning to the modal dialog again.

How can i do this? I am using Windows Forms.

Edit: AutoCAD does it well.

0
source share
6 answers

Just close the modal dialog. This is not like regular Form instances, so you just push it back by calling ShowDialog () again. Note that calling Hide () in a modal dialog box also closes it.

+2
source

Then I don’t think you want a modal dialogue ...

The whole purpose of a modal dialogue is that the user cannot do anything until he gets rid of it in any way. I think you should just create your own form class to act the way you would like.

+15
source

. Windows , .

, Enabled true. API EnableWindow Win32, .

+1

/ , , , , , . , , - / .

0

- .NET. () , , , .

Windows (API), .

, ( ​​ Enabled = false , Enabled = true ).

( NeedInteraction), , , - , .

void ShowDialog()
{
  var dialog = new MyModalForm();
  dialog.NeedInteraction += (sender, eventArgs) =>
  {
    dialog.Hide();
    Enabled = true;

    //wait till user finishes working with main window

    Enabled = false;
    dialog.Show();
  }

  Enabled = false;
  dialog.ShowDialog();
  Enabled = true; //don't forget to make it enabled afterwards
}

This may not be a clean solution (since you do not need to hide the modal dialog), but it works, at least for my situation.

0
source

Source: https://habr.com/ru/post/1527183/


All Articles