Child Form Focus

  • Thread starter Thread starter afrinspray
  • Start date Start date
No, but your code could be better. I don't understand why you're trying to hide an MDI Child form that is losing the focus. That doesn't make any sense to me. Under normal MDI operations, the parent MDIChildActivate will fire when the focus changes from one MDI Child to another, or when the last child is closed.

You don't have to have an array of names to check which form is the active one, instead you can use the Is operator to check object equality:

Visual Basic:
If Me.ActiveMDIChild Is frmObjectArray(1) Then

If you really must hide a child that goes out of focus, you could perhaps try the BeginLayout and EndLayout methods of the parent form, to indicate you're performing a multi-step operation and it shouldn't redraw or raise certain events.
 
Cool, I'll implement the object comparison change.

I can't find the BeginLayout or EndLayout methods anywhere. Are these in the vb library or do I have to write them myself?
 
I figured out a solution! Say I have the following forms: i-1, i and i+1, where i-1 is behind i which is behind i+1. In this example, i+1 is the active form. Before, when I'd click on i, my program would hide the top level form (i+1) and then automatically activate the i-1 form for some bizarre reason that I can't figure out. Then, the i form would also be activated, so I'd have to active looking windows, i-1 and i.

To fix the problem I explicitly told VB to activate both mdi forms in the order that I wanted them to be activated. So, I said

frmObjectArray(i-1).Activate()
frmObjectArray(i).Activate()

where frmObjectArray is my "collection" of forms. This is a total hack but it's the only way I could get only one form activated at once. Maybe someone has a better idea? I don't know, but it works- thanks for all the help.
 
I really don't follow your problem at all. I suspect if you need any more help on this issue you'll have to make a sample project which reproduces your problem and post it.
 
I know why you don't follow my problem! Because it had nothing to do with activation. The MDIForm was my startup form, and then the definstance function was creating another object (I think). So for some reason, when I would hide a form, one instance would have one active child form and then the other would have a different active child form. Somehow, VB was coordinating the two instances so that it would only show one active form, but there could be more than one active mdi child!

I can't really understand how it would do that. Maybe my explanation is wrong; however, I removed the DefInstance function in the MDIForm and the problem was solved!
 
Absolutely. But, I had significantly changed the code since then. The only part of the "upgrade support" that still remained was the MdiForm's DefInstance function.

I honestly had no idea that this had anything to do with the problem I was having. I also didn't know that two MdiForms could be open at the same time in VBNet. I understand it now though; VBNet is completely object oriented and all these forms are all objects. So it makes sense that two can be open.
 
Back
Top