|
-
Sep 24th, 2008, 10:10 AM
#1
Thread Starter
Frenzied Member
[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:
Public Class RollOverPanel
Inherits System.Windows.Forms.Panel
''' <summary>
''' Loops through each RollOver control and calls the triggeroff() method of said
''' controls. TriggerOn() changes the controls base color to its "hot" color.
''' </summary>
''' <remarks>Currently only the RollOverLabel control is tested</remarks>
Private Sub ActivateHotControls()
For Each Control In Me.Controls
If TypeOf Control Is RollOverLabel Then
Dim CurrentLabel As RollOverLabel
CurrentLabel = CType(Control, RollOverLabel)
CurrentLabel.TriggerOn()
End If
Next
End Sub
''' <summary>
''' Loops through each RollOver Control and calls the triggeroff() method of said
''' controls. TriggerOff() reverts from the controls "hot" color to its base color.
''' </summary>
''' <remarks>Currently only the RollOverLabel control is tested</remarks>
Private Sub DeactivateHotControls()
For Each Control In Me.Controls
If TypeOf Control Is RollOverLabel Then
Dim CurrentLabel As RollOverLabel = CType(Control, RollOverLabel)
CurrentLabel.TriggerOff()
End If
Next
End Sub
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
MyBase.OnMouseEnter(e)
ActivateHotControls()
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
'This is the offending line.
DeactivateHotControls()
End Sub
End Class
-
Sep 24th, 2008, 01:19 PM
#2
Thread Starter
Frenzied Member
Re: [2008] Working with custom mouse events
-
Sep 24th, 2008, 05:10 PM
#3
Thread Starter
Frenzied Member
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.
-
Sep 25th, 2008, 06:57 AM
#4
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|