What represents Sender

zhaozj2021-02-16  96

'Sender represents something

'My current understanding is that Sender represents the current instance, not the main body of the event.

'Please verify

Private sub button1_click (byvale 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 (byvalgend, 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" is Button3 is not Button1

End Sub

'This is more intuitive

DIM mstr as string = "Try"

Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click

If sender is mstr damox (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

转载请注明原文地址:https://www.9cbs.com/read-11444.html

New Post(0)