The situation is as follows:
I have an MDI application, several windows are open.
Apart from my application, I have other applications open such as Outlook and Internet Explorer
My application opens a modal selection form. (form.showDialog()).
When the selection is made I hide the modal form. This gives focus back to the main application form.
however
Part of the time (not all the time), after hiding the modal form, the application does not go back to my main form, but switches to a completely different progra, like internet explorer, or whatever is open. This problem did not occur on my development machine. My clients have slower systems then my development machine have reported this to me. After investigation, I can clearly see that slower computers have the problem much more often, up to 90% of the time.
This is all under windows XP. Under windows vista the problem occurs even on high-end machines.
Any help on this would be MUCH appreciated, as it is a big problem for my client. Obviously.
Thank you,
Jagg
Loading
JaggPosted Mar 18, 2008, 1:10 AM
I actually have to minimize and maximize my application for it to be on the foreground again. (or minimize the other application)
Additional note: The problem does not occur if I close and recreate the form each time it is used. But I would really like to avoid this as a lot of calculations happen on the form, after which the user can select from it.
Scott LyslePosted Mar 15, 2008, 5:09 AM
If you want to guarantee that the focus will return to the form used to launch it, in your modal dialog, you could change the constructor accept a form of the type used to launch the dialog and then, in the form closed event, set the focus back to the calling form:
Form1 parentForm1; public MyDialog(Form1 parent) { InitializeComponent(); parentForm1 = parent; } private void MyDialog_FormClosed(object sender, FormClosedEventArgs e) { parentForm1.Focus(); } Of course you'd then launch the dialog like this: private void button1_Click(object sender, EventArgs e) { MyDialog d = new MyDialog(this); d.ShowDialog(); }