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
this is exactly the definition of a Delegate. Check https://msdn.microsoft.com/en-us/library/ms172879.aspx
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.
ASKER
Can you elaborate please ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.