.net 使用方法参数路由我的事件

.net 使用方法参数路由我的事件,.net,vb.net,.net,Vb.net,我只是有一个关于在调用方法中添加一个目标方法作为变量参数的简短问题 我想将TextChanged事件发送到一个特殊的文本框。但是我想在我的方法中有一个“变量”来将处理程序添加到文本框中。因为可以更改文本框,然后我可以更改“更改的事件”应该路由到的处理程序 我应该用什么替换下面的问号 Dim TextBox1 as TextBox Dim TextBox2 as TextBox Private Sub DoIt Call TestRouting(TextBox1, TextBox_TextCha

我只是有一个关于在调用方法中添加一个目标方法作为变量参数的简短问题

我想将
TextChanged
事件发送到一个特殊的文本框。但是我想在我的方法中有一个“变量”来将处理程序添加到文本框中。因为可以更改文本框,然后我可以更改“更改的事件”应该路由到的处理程序

我应该用什么替换下面的问号

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

这就是你想做的吗

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

在本例中,为了便于说明,每次文本更改时,我都会更改所发生的情况。

这就是您要做的吗

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

在本例中,为了便于说明,每次文本更改时,我都会更改发生的情况。

我想调用
act1
act2
act3
,当使用其中一个ACT的参数调用
TextBox1\u TextChanged
时。在参数
e As Action
中,应该是
act?
中的一个,然后我可以调用
actX
的methode,它没有接口,只有methode描述。我想调用
act1
act2
act3
,当使用其中一个act的参数调用
TextBox1\u TextChanged
时。在参数
e As Action
中,应该是
act?
之一,然后我可以调用
actX
的methode,它没有接口,只有methode描述。