ShowDialog problem

  • Thread starter Thread starter Chris Capel
  • Start date Start date
C

Chris Capel

Hey everyone.

If you call ShowDialog on a form from the main thread of an application, it
behaves like a modal dialog. However, if you call ShowDialog from a
different thread, using the default overload, it behaves like you called
Show. If you assign the parent, the "modal" form stays on top of the parent
but does not prevent input to the parent.

This makes it hard for me to accomplish what I'm trying to do: show a modal
dialog that says "Loading..." when the user takes an action that could be a
while to finish. It needs to stay on top of the main form and prevent input
to the main form just like a modal dialog, but it can't block the execution
of the main thread because that's where the work is being done.

Anyone have any ideas?

Chris
 
I haven't tried this, but what if you pass a reference of the main window to
the function in the other thread, then call a function in the main thread
that calls the modal window? Or show the modal window first, and then start
a thread for the function from the modal window?

HTH,
Lars-Erik
 
Hi Chris

I had the same Problem, so I started playing with the Form-Properties.
Here is a solution, that makes your statusForm behave like a modal Dialog to your mainForm, but execution is not blocked.

{
statusForm.Owner = mainForm;
mainForm.Enabled = false;

statusForm.Show();

// do Loading Work here

statusForm.Hide();
mainForm.Enabled = true;
}

The importance seems to be, that you disable the owner-form before you call the Show() method.

Hope it helps,
Markus

By the way: Do you know a way to display a Form modal to another Form in a way, that it doesn't block the interaction with other forms. Because if I call the ShowDialog method with another form as parameter, all other forms are disabled, even if they are not owned

Hey everyone.

If you call ShowDialog on a form from the main thread of an application, it
behaves like a modal dialog. However, if you call ShowDialog from a
different thread, using the default overload, it behaves like you called
Show. If you assign the parent, the "modal" form stays on top of the parent
but does not prevent input to the parent.

This makes it hard for me to accomplish what I'm trying to do: show a modal
dialog that says "Loading..." when the user takes an action that could be a
while to finish. It needs to stay on top of the main form and prevent input
to the main form just like a modal dialog, but it can't block the execution
of the main thread because that's where the work is being done.

Anyone have any ideas?

Chris

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
 
Back
Top