Reputation: 4900
I just have a short question about adding an destination method as variable argument into my calling method.
I want to send a TextChanged
event to a special textbox. But I want to have a "variable" in my method to add the handler to the textbox. Because it is possible to change the textbox and then I can change the handler where the "Changed Events" should be routed to.
What should I replace the question marks below with ???
Dim TextBox1 as TextBox
Dim TextBox2 as TextBox
Private Sub DoIt
Call TestRouting(TextBox1, TextBox_TextChanged)'I want to submit the methode where the changed event should route to
End Sub
Private Sub TestRouting(byval Obj as TextBox, byval ChangedAction as ???)
Addhandler Obj.TextChanged, AddessOf ChangedAction
End sub
Private sub TextBox_TextChanged(byval sender as object, byval e as args)
'do something
End Sub
Upvotes: 1
Views: 51
Reputation: 11773
Is this what you are trying to do?
Dim someAction As New Action(AddressOf act1)
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
someAction()
End Sub
Private Sub act1()
Debug.WriteLine("act1")
someAction = New Action(AddressOf act2)
End Sub
Private Sub act2()
Debug.WriteLine("act2")
someAction = New Action(AddressOf act3)
End Sub
Private Sub act3()
Debug.WriteLine("act3")
someAction = New Action(AddressOf act1)
End Sub
In this example I changed what happened every time the text changed for illustration purposes.
Upvotes: 1