Link to home
Start Free TrialLog in
Avatar of Waterside
Waterside

asked on

Passing a Method ?

Is there a way that I can add a property to a class that I can then use to fire given method ?

Public Class Box
   Public name As String
   Public size As Double
   Public mouseentermethod As Method ?????
End Class

Public Sub drawBox(box As Box)
        With box
                    Dim rect As New Rectangle
                    rect.Name = .name
                    rect.Width = .size
                    rect.Height = .size
                    rect.Fill = New SolidColorBrush(Colors.Red)
                    grd.Children.Add(rect)

                    ' call the method associated with this instance of the Box Class
                    AddHandler rect.MouseEnter, AddressOf .mouseentermethod
        End With
End Sub

Open in new window

Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

this is exactly the definition of a Delegate. Check https://msdn.microsoft.com/en-us/library/ms172879.aspx
Avatar of Waterside
Waterside

ASKER

Ok.  What type do I make .mouseentermethod in the Class to be able to use it with the AddHandler ?
I would point the AddHandler to a real method that exist in that class and that method would call the delegate.
Can you elaborate please ?
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial