switch focus between modal forms?

  • Thread starter Thread starter Ed White
  • Start date Start date
E

Ed White

If I have, say, Microsoft Excel open on the left screen, and Microsoft Word
open at the same time on the right screen, then I can move the mouse cursor
over Excel and click on it, and Excel gets activated, and I can then move the
mouse cursor over the Word screen, click on it, and Word gets activated.

I'm writing a program using two Windows Forms in VB.Net (VS 2008), and I'd
like to do the same thing. That is, I'd like to have two windows open next
to each other, and each one of them would be modal/activated when I click on
it. (What doesn't work is, for example, is if I open one form with Fm1.Show
and the 2nd with Fm2.ShowDialog, then I can't activate Fm1.) Is there a way
to do this?
 
Ed said:
If I have, say, Microsoft Excel open on the left screen, and
Microsoft Word open at the same time on the right screen, then I can
move the mouse cursor over Excel and click on it, and Excel gets
activated, and I can then move the mouse cursor over the Word screen,
click on it, and Word gets activated.

I'm writing a program using two Windows Forms in VB.Net (VS 2008),
and I'd like to do the same thing. That is, I'd like to have two
windows open next to each other, and each one of them would be
modal/activated when I click on it. (What doesn't work is, for
example, is if I open one form with Fm1.Show and the 2nd with
Fm2.ShowDialog, then I can't activate Fm1.) Is there a way to do this?

In one (UI) thread, you can only activate one modal window. You'd have to
open two modal windows in different threads. Don't know if it makes sense in
your case.

Or you can open a modeless window after opening the modal
window, so you are able to switch between the modal and the modeless
window.


Armin
 
You said
"Or you can open a modeless window after opening the modal
window, so you are able to switch between the modal and the modeless
window."

After opening a modal window, the program is essentially in standby mode
waiting for events from the modal window or for the modal window to close.
How do I open a modeless window after opening a modal window? (I did try
using the Fm1.Activated event to open a second window using Fm2.Show, but Fm2
cannot be activated by clicking on it.)
 
Ed said:
You said
"Or you can open a modeless window after opening the modal
window, so you are able to switch between the modal and the modeless
window."

After opening a modal window, the program is essentially in standby
mode waiting for events from the modal window or for the modal window
to close. How do I open a modeless window after opening a modal
window? (I did try using the Fm1.Activated event to open a second
window using Fm2.Show, but Fm2 cannot be activated by clicking on it.)

I tested it this way: (I wasn't sure what happens if a modeless form is
opened from a modal form)
- new project including default Form1
- add 2 new forms
- one button on Form1 and one on Form2
- Click Button Form1: create form2 + showdialog
- Click Button Form2: create form3 + show
- run, click button, click button

I am able to switch between form2 and form3.


Armin
 
That works, more or less. The only problem is that Fm3 becomes minimize
whenever I click on Fm2, even if they are on different screens.

The problem I'm dealing with is that I just acquired a fourth monitor. When
I had three monitors, they were all horizontall across my desk, forming one
large flat rectangle. When I got the 4th monitor, I mounted the 2 left
monitors on a vertical stand (one on top of the other), but left the 2 right
ones remain horiztonal at eye level. So now, instead of having a rectangular
desktop, it looks like a sideways 'T' with the head of the T on the left. As
far as I know, you cannot make a T-shaped windows form, so I'm looking at
various ways of utilizing the entire desktop on a windows form. One idea I
had is to make a form as tall as the 2 vertical ones and as wide as the 3
across, and put in Panels where each screen is, leaving unused window space
above and below the 2 right screens. The only problem with that is that the
minimize, maximize, and close controls are always on the upper right of the
form, so I can't see them when I do this (do you have a workaround?) Another
possible solution is to create 2 windows, one for the 2 left vertical
monitors, and the other for the 2 right horizontal ones, but that creates the
issues with focus, threading, etc. that I've been asking about here.
 
FYI--As for the Fm3 becoming minimized whenever I clicked on Fm2, I added an
event to Fm3 that sets the WindowState=Normal for Fm2 whenever Fm3 becomes
activated, and as long as the 2 forms are on different screens, it seems to
work like I want.
 
Back
Top