Hi guys,

I came across an issue I had not expected when I was writing up my custom panel control. Apparently when the mouse enters a panels children it triggers a mouse leave event on the panel. This means my code does not work. I can update the custom children because the panels children need not only be custom controls. I'm kind of stumped. I though about looking to see if the mouse is in the panels border but im unsure of how to do this and imagine that the mouse would be considered out of bounds when it enters the children. Any suggestions?

VB Code:
  1. Public Class RollOverPanel
  2.     Inherits System.Windows.Forms.Panel
  3.  
  4.     ''' <summary>
  5.     ''' Loops through each RollOver control and calls the triggeroff() method of said
  6.     ''' controls. TriggerOn() changes the controls base color to its "hot" color.
  7.     ''' </summary>
  8.     ''' <remarks>Currently only the RollOverLabel control is tested</remarks>
  9.     Private Sub ActivateHotControls()
  10.         For Each Control In Me.Controls
  11.             If TypeOf Control Is RollOverLabel Then
  12.                 Dim CurrentLabel As RollOverLabel
  13.                 CurrentLabel = CType(Control, RollOverLabel)
  14.                 CurrentLabel.TriggerOn()
  15.             End If
  16.         Next
  17.     End Sub
  18.  
  19.     ''' <summary>
  20.     ''' Loops through each RollOver Control and calls the triggeroff() method of said
  21.     ''' controls. TriggerOff() reverts from the controls "hot" color to its base color.
  22.     ''' </summary>
  23.     ''' <remarks>Currently only the RollOverLabel control is tested</remarks>
  24.     Private Sub DeactivateHotControls()
  25.         For Each Control In Me.Controls
  26.             If TypeOf Control Is RollOverLabel Then
  27.                 Dim CurrentLabel As RollOverLabel = CType(Control, RollOverLabel)
  28.                 CurrentLabel.TriggerOff()
  29.             End If
  30.         Next
  31.  
  32.     End Sub
  33.  
  34.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  35.         MyBase.OnMouseEnter(e)
  36.         ActivateHotControls()
  37.     End Sub
  38.  
  39.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  40.         MyBase.OnMouseLeave(e)
  41.         'This is the offending line.
  42.         DeactivateHotControls()
  43.     End Sub
  44.  
  45. End Class