Modeless dialog and the main form

  • Thread starter Thread starter proit_123
  • Start date Start date
P

proit_123

I am working on a windows forms application and have the following
requirement.

· I need to display a modeless dialog from the main form.
o This allows user to continue to work with the application.
o For the sake of example, the user could launch the modeless dialog
from Form A and navigate to a Form B in the main window.
· When the modeless dialog is closed, I need to perform certain logic
in the main form based on the form that is loaded in the main window.

Can somebody please suggest a way to achieve this?

Thanks,
SK
 
You can tie the form closed event
http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.closed.aspx
and just show it as a normal form.

Form f = new YourForm();
f.Closed += new EventHandler(SomeMethodOnYourMainForm);
f.Show();

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

I am working on a windows forms application and have the following
requirement.

· I need to display a modeless dialog from the main form.
o This allows user to continue to work with the application.
o For the sake of example, the user could launch the modeless dialog
from Form A and navigate to a Form B in the main window.
· When the modeless dialog is closed, I need to perform certain logic
in the main form based on the form that is loaded in the main window.

Can somebody please suggest a way to achieve this?

Thanks,
SK
 
I am working on a windows forms application and have the following
requirement.

· I need to display a modeless dialog from the main form.
o This allows user to continue to work with the application.
o For the sake of example, the user could launch the modeless dialog
from Form A and navigate to a Form B in the main window.
· When the modeless dialog is closed, I need to perform certain logic
in the main form based on the form that is loaded in the main window.

Can somebody please suggest a way to achieve this?

If Greg Young's answer sufficies, then ignore me, but to me it sounds
like you might mean that when ModelessForm closes, you want to do
something in *whichever main form is _currently_ active*, not just
whichever form spawned ModelessForm.

If this is the situation: then ModelessForm is going to need some way to
'keep track' of which main form is currently the 'active' main form. So
ModelessForm will have a Form member to keep track of this (perhaps an
IMainForm, with IMainForm being implemented by all main forms, and
containing the 'certain logic' that needs to be performed here).

However - we don't really want the main forms to have to check who cares
about which one of them is active. So how about we have an app-level
event ActiveMainFormChanged, which the ModelessForm can subscribe to,
and the main forms can raise every time they become active.

Then ModelessForm can update its IMainForm member whenever it hears an
ActiveMainFormChanged event, and on its own Close it can call
IMainForm.CertainLogic on what it can be sure is the currently active
main form.

Sometimes these things are quicker to code than to explain! :)
 
Back
Top