C # The use of events in Form 2 triggers Form 1 so that form 1 executes a method

Source: Internet
Author: User

Step 1: in Form 2

Define Delegation

Define events

 
Public Delegate VoidChange (StringNewsendemails );//The definition of Delegate and delegate should be the same as the actual method in the UIPublic EventChange mychangeevent;//Define events

In a method or event

Execution event

 
Mychangeevent (sb. tostring ());//Execution event

Step 2: in Form 1

Define a method (event execution method) that corresponds to the form parameter and return value of Form 2 Delegate)

//Event execution MethodPublic VoidSetsendemail (StringNewemails ){This. Textboxsendemaillist. Text =Newemails ;}

Register events in Load

Private VoidButtonsendemailsum_click (ObjectSender, eventargs e) {formsendemailsift fromsendemailsift=NewFormsendemailsift (This. Qqentitylist); fromsendemailsift. mychangeevent+ =NewFormsendemailsift. Change (setsendemail );//Register an eventFromsendemailsift. Show ();}

In this way, you can click a button in Form 2 or execute a method in Form 1 to execute the method you want.CodeNow

To directly pass values in different forms

 

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.