. NET Events Mimic button buttons

Source: Internet
Author: User

The first thing to start touching is when the command is Webfrom, the time to drag the control, and then directly write the click event, which may be preconceived thought,

Coupled with the use of events too little, resulting in contact with the command mode, CQRS, publish subscription mode when the event this piece is not understood,

So deepen your understanding, here we use the console to simulate a button

1  Public  classButton2     {3         //to define a delegate that invokes an event4          Public Delegate voidButtondelegate (stringe);5 6         //button stand-alone event7         Private Eventbuttondelegate Buttionclick;8 9         //Adding and removing eventsTen          Public Eventbuttondelegate click_event One         { AAdd { This. Buttionclick + =value;} -Remove { This. Buttionclick-=value;} -         } the  -         //Triggering Events -          Public voidRaiseclick (stringargs) -         { +Buttionclick?. Invoke (args); -         } +}

The event is also a member of the class, he is not the same as the property, and the action event is via add and remove

1  class Program2     {3         Static voidMain (string[] args)4         {5Button B =NewButton ();6B.click_event + =Newbutton.buttondelegate (button_click);7B.click_event + =Newbutton.buttondelegate (BUTTON_CLICK1);8 9B.raiseclick ("Hello");Ten  One console.readline (); A         } -  -         Private Static voidButton_Click (stringargs) the         { - Console.WriteLine (args); -         } -  +         Private Static voidButton_click1 (stringargs) -         { + Console.WriteLine (args); A         }

Here's a brief description of how the event is defined, and the next step is to make a simple publish subscription.

. NET Events Mimic button buttons

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.