1
Reply

redirect focus from one MDI child form to another

jeffrey_a_hale

jeffrey_a_hale

Apr 15 2004 10:17 AM
4.6k
I've written a customer windows manager which controls which form should get focus (it allows me to treat forms as "selectably modal" - ie normally you can't click off a form but you can onto certain other forms). Ex: I may have a dialog box form that pops up off a parent form. I shouldn't be able to click off the dialog form back to the parent (without hitting ok or cancel), but I may want to click onto another form that may have some data not visible that I need to scroll to. So this dialog form isn't really modal, but my window manager will prevent me clicking onto other forms that shouldn't be allowed to receive the focus. All my forms extend a base form. The base forms has an Activate event handler that checks with the Window Manager to see if it's allowed to receive the focus. If it shouldn't get the focus, it gets a reference to the form that should have the focus from the Window Manager and calls it's focus method. This works fine for normal forms. Ex: say this is my Form1 activated event handler: private void Form1_Activated(object sender, System.EventArgs e) { if(form2!=null) form2.Focus(); } Obviously this is a contrived example. But this is the idea. Form1 would get a reference to Form2 from the WindowManager (Form2 is the form that should keep the focus) and form2's focus event is called. My problem is all my forms are MDI children of a main form. This code does nothing in that case. If these forms aren't MDI children, it works fine. Is there a way around this, to make it work? I like having the MDI parent, so I can have my Window menu item. I don't want to do a hack where it looks like MDI but isn't really.

Answers (1)