views:

53

answers:

2

Im writing a new plugin based app. This loads assemblies in their own app domains and displays the specified main forms within each via Application.Run(pluginForm). I set the main form in the loader app as the parent of each pluginForm before calling Application.Run(pluginForm) inside the app domain. Hence when the pluginForm shows it always gets displayed in front of the mainForm of the loader app.

My problem is when a user clicks for the first time on the pluginForm (child form), it looses focus and the mainForm (loader app's form) gets focus. (However the pluginForm stays in front) Hence the user ends up having to click twice to get the pluginForm to focus for the first time.

This is pretty annoying. How can I fix this?

+2  A: 

You should show the child forms as modal dialogs on the parent's UI thread by calling ShowDialog().

SLaks
Thanks. Yes, I have tried this. But this will limit me to a single form at a given time. I need multiple such forms to be up and about. I have also tried pluginForm.Show() in a seperate thread other than the parent UI thread. This elliminates the set focus bug however I cannot set pluginForm.Owner to the mainForm since it is in a seperate thread. Any other ideas?
Harindaka
A: 

When you call the child Forms use

childForm.ShowDialog(parentForm);

OR the equivalent

childForm.ShowDialog(this);
Michel Triana
Thanks. The fact is im doing this from a different thread other than the main UI thread. :(
Harindaka