Question : C#: Alternative to Modal window

I'm developing a .NET windows app that has "lookup" windows to allow users to select values for certain fields on the main form.  Normally, these lookup windows would be modal.

However, due to a bug in an integration framework that I'm having to use, I am unable to use any modal windows.  (long story, it's a pain)

Are there workarounds that would allow me to manually handle situations that modal windows normally take care of?

The two issues that come to mind are:

1) When a lookup window is open and the user clicks on another window, I need to either set the focus back on the lookup window, or close the lookup window and return focus to the main form.  I can close the lookup window on the Deactivate event, but is there a way to set the focus back to the main form of the app?  (or can I setup a parent / child relationship between the main form and lookup windows?)

2) How do I prevent the user from opening more than one instance of a lookup window?  Currently, if the lookup is non-modal, the user can open multiple lookup windows.


Are there any other issues that I need to consider?

Answer : C#: Alternative to Modal window

A simple approach is to DISABLE the main form so that the user can't interact with it:

    this.Enable = false;
    // ...display your "modal" form...

You can subscribe to the FormClosed() event of the "modal" form so you know when to re-enable the form.

Since the user can't interact with the disabled from they also can't open up multiple instances of your "modal" form.
Random Solutions  
 
programming4us programming4us