C # code tutorial for executing another button with one button,

Source: Internet
Author: User

C # code tutorial for executing another button with one button,

For example, the first button protected void button#click (object sender, EventArgs e ){//?????????? } Second button protected void Button2_Click (object sender, EventArgs e) {button#click (sender, e );}

The second one can use the code of the first button

======================================================== ========================================================== =

You can use delegation to implement this !!

Code!

This. button3.Click + = new System. EventHandler (button2_Click );

Let me explain it to you ~ The previous this. button3.Click is the click event that calls button2!

See it ~ This code is written in the click event of button3!

(Button2_Click) is the method of the click event to be called!

========================================== ======================================

In fact, you are talking about the two buttons to execute the same method. You can define a method. In fact, you double-click the button in it, not an event definition method private void Fun (object sender, EventArg e) {// do something ;} the parameters in this method must be those two and then add two statements to the constructor of this program. This constructor refers to the function button1.Click + = new EventHandler (Fun) in your program set ); button2.Click + = new EventHandler (Fun );

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.