Home All Groups Group Topic Archive Search About
Author
29 Jun 2005 7:58 AM
Sam
Hi,

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



Thx

Author
29 Jun 2005 9:44 AM
Larry Lard
Sam wrote:
Show quoteHide quote
> Hi,
>
> 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

It looks like you have the syntax slightly muddled. I think you just
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
Author
29 Jun 2005 9:52 AM
Sam
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
Author
29 Jun 2005 9:56 AM
Sam
oups sorry, was just function to replace with sub...

I'm testing now.
Author
29 Jun 2005 10:01 AM
Sam
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 ?!?!
Author
29 Jun 2005 10:13 AM
Sam
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.MouseEven­tArgs)
is still my panel instead of being the child control...
Why ?