Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I can't figure out how to detect when an active MDI Child Form has been deactivated. The Deactivate event works on non-MDI forms but doesn't fire on MDI Child Forms.

 

There is no corresponding Deactivate event to the MdiChildActivate event. MdiChildActivate works fine. I probably could do a workaround on that, but I'd rather figure out what event gets called.

 

I tried Leave and OnLostFocus, but they often fire even as the same Child Form remains active. What event should I use?

Posted

I don't know what kind of problem you have... It works just fine for me! I use it a lot on one of my current projects!

 

Do you wnat to pass the event to the MDI to control something?

If so you have to Raise an Event that will be catchedby the MDI Parent...

 

I'll post here the code that works for me... The idea is to pass an Event to the MDI whenever a MDIChild is Activated or Deactivated, Showing o Hiding the correnpondent Toolbox on my DevExpress ToolBar Control that is placed on the MDI Parent.

 

   Private Sub frmFichasReclusos_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       RaiseEvent ReclusosBarVisible(True)
   End Sub

   Private Sub frmFichasReclusos_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       RaiseEvent ReclusosBarVisible(False)
   End Sub

 

 

Tell me if you have any doubts or if it isn't what u wanted ...

Software bugs are impossible to detect by anybody except the end user.
  • *Gurus*
Posted

You can use the parent's MdiChildActivate event for both purposes. When it fires and there is only one child window open, you've just opened your first child. When it fires after that it means that one has just been deactivated in favour of the new one, obviously. You can keep a reference to the currently active window if you need to determine which one was deactivated.

 

The event will fire once more when the last child window is closed, and then the parent ActiveMdiChild property will be null.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Thanks, Divil. That's the approach I decided to use. Here's the code I came up with:

 


'MDI parent-level declare
Private mPrevChildForm As Form

Private Sub MdiChildActivateDeactivate(ByVal sender As Object, _
	ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
	
  ' Determine the active child form.
  Dim activeChild As Form = Me.ActiveMdiChild
  
  If Not activeChild Is Nothing Then
     'Only deal with Business forms
     'All my MDI Child forms are inherited from BusinessForm
     If TypeOf activeChild Is BusinessForm Then
     	'The first time in, mPrevChildForm should be Nothing
        If Not mPrevChildForm Is Nothing Then
      	'Run my version of Deactivate
           DirectCast(mPrevChildForm, BusinessForm).bizDeactivate()
        End If
      'Save current active form and run my version of Activate
        mPrevChildForm = activeChild
        DirectCast(mPrevChildForm, BusinessForm).bizActivate()
     End If
  End If
  
End Sub
  

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...