0

My problem is that when the subroutine runs I don't know which button caused it to be triggered how can I find this out. The variable count needs to be replaced with the delete button number that was clicked. I cannot have a separate subroutine for each button as I don't know how many the user needs to be added to the form on each occasion.

    Dim delete1 = Sub()
        .Remove(label1(count, 1))
        .Remove(combo1(count, 1))
        .Remove(label1(count, 2))
        .Remove(combo1(count, 2))
        .Remove(label(count, 3))

                 End Sub

    For counter = 1 To count
        AddHandler MyClass.button1(counter).Click, delete1
    Next
4

1 回答 1

3

你可以从sender参数中得到它:

Private Sub delete1(sender As System.Object, e As System.EventArgs)

    Dim curButton As Button = DirectCast(sender, Button) 'Button you clicked

End Sub

请注意,直接添加上述功能的代码(不带delegate)是:

AddHandler MyClass.button1(counter).Click, AddressOf delete1
于 2013-11-07T15:32:52.240 回答