How to: Call the button's Click Event programmatically (Visual C #)

Source: Internet
Author: User

Http://msdn.microsoft.com/zh-cn/library/hkkb40tf (vs.90). aspx

Updated: February 1, November 2007

Even if you do not click a button, you can use the javasmclick method to programmatically trigger the button click event. The following example shows how to call a button click event in a program. When you click button2, The Click Event of button1 is also triggered.

Use buttons in programs
  1. On the File menu, click New project ".

  2. In the "Create Project" dialog box, in the "template" pane, click "Windows Forms Application", and then click "OK ".

    A new windows form project is opened immediately.

  3. Drag two button controls from the toolbox to the form.

  4. In the form, double-click the first button (button1) to create the click event handler.

  5. In the button#click event handler, type the following code line.

  6. MessageBox. Show ("button1.click was raised .");

  7. Right-click the code and click View designer ".

  8. Double-click the second button (button2) to create the click event handler.

  9. In the button2_click event handler, type the following code line.

  10. // Call the click event of button1.

  11. Button1.w.mclick ();

  12. Press F5 to run the program.

  13. The program starts and a form is displayed. When you click button1 or button2, the click event handler of button1 displays a message.

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.