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 に答える