Home >Backend Development >C++ >How Does Event Handling Work in C#?
In -depth understanding of the event processing in C#
Incident detailed explanation
In the user interface, the incident represents a move to respond to the user input or other system events. The event statement is as follows:
Event processing procedure and its importance
<code class="language-c#">public void EventName(object sender, EventArgs e);</code>Event processing procedure is a method executed during the event. They are essential for response events and execute the required operation, for example:
Update the user interface according to the change of the data source
Navigation to the new page in the web application
Define a signature (return type and parameter) to the method to be executed.
Create an event using the commission as a signature.Implement the processing procedure that conforms to the entrusted signature.
In this example:
MyEventhandler entrusts the method to return VOID and accepts string parameters.Somethinghappending Event uses MyEventhandler as its signature, allowing it to call the event processing program that conforms to the signature.
<code class="language-c#">// 委托 public delegate void MyEventHandler(string foo); // 事件 public event MyEventHandler SomethingHappened; // 事件处理程序 void HandleSomethingHappened(string foo) { // 当 SomethingHappened 触发时执行的代码 } // 订阅事件处理程序 myObj.SomethingHappened += new MyEventHandler(HandleSomethingHappened); // 触发事件 SomethingHappened("bar");</code>
Handlesomythinghappened method was created as an event processing program.
The above is the detailed content of How Does Event Handling Work in C#?. For more information, please follow other related articles on the PHP Chinese website!