Results 1 to 4 of 4

Thread: [2008] Working with custom mouse events

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    [2008] Working with custom mouse events

    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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: [2008] Working with custom mouse events

    Bump for help.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: [2008] Working with custom mouse events

    Sorry post makes no sense, just very tired.
    Last edited by DeanMc; Sep 24th, 2008 at 05:20 PM.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: [2008] Working with custom mouse events

    Ok, I think i may know in theory how to do this. As far as I can see on MSDN the panel.location returns the panels X and Y cordinates as a rectagle. If I create a new rectangle with these values plus the size of the panel control like so

    Dim MyRec as Rectangle
    MyRec.X = Panel.Location.X
    MyRec.Y = Panel.Location.Y
    MyRec.Size = Panel.Size

    I should get a Rectangle that is the same size as the panel at the same location from what I read. The issue seems to be that the mouse cordinates map to the screen rather than the client form. Where as i imagine that the cordinates of my rectangle map to the client form because thats what the panel maps to. This means that these two wont match. The other side of it is that my development PC has two monitors and this could be squewing my values even further.

    Any Insight to this guys?
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width