'Sender代表什么
'我目前的理解是,Sender代表当前实例,而不是发出事件的主体
'请验证
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Console.WriteLine(sender.ToString)
'return "System.Windows.Forms.Button(, Text) : Button1()"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Console.WriteLine(sender.ToString)
'return "System.Windows.Forms.Button(, Text) : Button2()"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Button1_Click(sender, e)
'return "System.Windows.Forms.Button(, Text) : Button3"是Button3而并非是Button1
End Sub
'这样更直观了
Dim mStr As String = "试试"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If sender Is mStr Then MsgBox(sender.ToString)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Button1_Click(mStr, e)
End Sub