|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
get mouseeventargsProtected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs) AddHandler e.Control.MouseMove, DirectCast(CheckCursor(), System.Windows.Forms.MouseEventHandler) End Sub The above code is to redirect the MouseMove event of any controls added to my panel to the method CheckCursor. This works except that CheckCursor needs the MouseEventArgs you would normally pass to it. How can I get it for the current child control ? Public Function CheckCursor(ByVal e As System.Windows.Forms.MouseEventArgs) As Object Thx Sam wrote:
Show quoteHide quote > Hi, It looks like you have the syntax slightly muddled. I think you just> > Protected Overrides Sub OnControlAdded(ByVal e As > System.Windows.Forms.ControlEventArgs) > AddHandler e.Control.MouseMove, DirectCast(CheckCursor(), > System.Windows.Forms.MouseEventHandler) > End Sub > > The above code is to redirect the MouseMove event of any controls added > to my panel to the method CheckCursor. This works except that > CheckCursor needs the MouseEventArgs you would normally pass to it. How > can I get it for the current child control ? > > Public Function CheckCursor(ByVal e As > System.Windows.Forms.MouseEventArgs) As Object need to do a AddHandler e.Control.MouseMove, AddressOf CheckCursor (note the AddressOf here) and make CheckCursor have the correct signature: Public Function CheckCursor(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) As Object and you are done. Note that DirectCast'ing to xxxHandler isn't really meaningful: the procedure either has the right signature to be a xxxHandler or it doesn't. -- Larry Lard Replies to group please thx.
but it still don't work : Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs) AddHandler e.Control.MouseMove, AddressOf CheckCursor End Sub Public Function CheckCursor(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Object gives : Method 'Public Function CheckCursor(sender As Object, e As System.Windows.Forms.MouseEventArgs) As Object' does not have the same signature as delegate 'Delegate Sub MouseEventHandler(sender As Object, e As System.Windows.Forms.MouseEventArgs)'. Can you help further ? thx Ok I've got the following code now :
Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs) AddHandler e.Control.MouseMove, AddressOf CheckCursor End Sub Public Sub CheckCursor(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If Not m_chkAnchor.Checked Then Dim pt As New Point(e.X, e.Y) If Not DirectCast(sender, Control).ClientRectangle.Contains(pt) Then Collapse() End If End If End Sub and in the constructor of my inherited panel control: AddHandler Me.MouseMove, AddressOf CheckCursor There are 3 different cases now: -mouse moves in panel and leaves -> collapse OK -mouse moves in child control only -> not collapse -mouse moves in panel and then in child control and then leaves -> collapse OK I don't understand what';s going on here ?!?! After debugging, I've noticed that in case the mouse moves in the panel
and then in the child control, the sender in Sub CheckCursor(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) is still my panel instead of being the child control... Why ? |
|||||||||||||||||||||||