Child Form Focus

  • Thread starter Thread starter afrinspray
  • Start date Start date
No, but your code could be better. I dont understand why youre trying to hide an MDI Child form that is losing the focus. That doesnt 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 dont 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:

Code:
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 youre performing a multi-step operation and it shouldnt redraw or raise certain events.
 
Cool, Ill implement the object comparison change.

I cant 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 Id 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 cant figure out. Then, the i form would also be activated, so Id 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 its the only way I could get only one form activated at once. Maybe someone has a better idea? I dont know, but it works- thanks for all the help.
 
I really dont follow your problem at all. I suspect if you need any more help on this issue youll have to make a sample project which reproduces your problem and post it.
 
I know why you dont 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 cant 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!
 
Definstance? Was this the product of you running VB6 code through the upgrade wizard?
 
Absolutely. But, I had significantly changed the code since then. The only part of the "upgrade support" that still remained was the MdiForms DefInstance function.

I honestly had no idea that this had anything to do with the problem I was having. I also didnt 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