Little experience regarding custom events

xiaoxiao2021-03-06  45

When searching in an article on MSDN, I accidentally saw a part of the custom event. The basics used throughout the day is basically the combo event of the IDE in the Windows development environment. For example, what is Click, I didn't understand it. I checked the book, I understood it slightly and deepened the impression. Although I have used an incident in Java, I must first define a delegate, and I will be chaotic.

First define an event's function signature (parameter format) - agent

public

Delegate void

ComputeSalaryCallback (String Empid, Double Salry);

Declare the event name included in the type, the logic triggered with the event

public

Event ComputeSalaryCallback

Oncomputesararydone;

In a function, declare the logic triggered by the event, in other words, when the following functions are called, trigger the onComputeSaRARYDONE Event:

Public Virtual Double ComputeSalary ()

{

OncomputeSararydone (MSTREMPID, MDBLBASSAlary); Return Mdblbasesalary;

}

Define the event handler, and connect the event to the event handler, the connection is like entrusting the function.

Public static void

SalaryHander

String Empid, Double Salry)

{

Console.weiteline ("employee: employee code = {0}, salary = {1}", EMPID, SALARY

}

OnComputeSaRARYDONE = New

ComputeSalaryCallback

SalaryHandler;

The above has completed the overall event. Once the computesalary () function is called, the event oncomputesalarydone is triggered, and the event handler is triggered. If you connect to multiple event handlers, the time handler function of the connection is performed in turn.

Alternatively, the event definition can be placed in the component, and then declare the event handler in other classes, processes.

转载请注明原文地址:https://www.9cbs.com/read-80080.html

New Post(0)