Sender in. NET control events

Source: Internet
Author: User

Private void button2_click (object  sender, RoutedEventArgs e) {}
Look at the WPF content recently, and look back. NET everyone is using it every day, but it is not an object of great concern----sender

Q: What exactly is sender?

A: All the events in the server control will have (probably too absolute, should say mostly), sender refers to the control that triggers the event.

  Private void button2_click (object  sender, RoutedEventArgs e)        {            = (Button) sender;// Method one             "kick [email protected]";             // button2. Content = "Kick ME";//Method two        }

Here is the core of the sender, what is the control that triggers the event?

There are two buttons on the interface (this is a WPF program, when 2 buttons are bound to a Click event button2_click↑).

button2_click the method of this event to change the name of the button. Point "button One" will become " "and point" button Two "will also become " kick [email protected] "This is the description sender refers to the control that triggers the event!

If you follow Button2_Click The method of this event two to change the name of the button. Click "button One" will make the button two "kick [email protected]", point "button Two" will not have any reaction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.