How to customize events in C #?
Wason (Zhuhai)
Only one example is used, how to use custom events in C #.
Write a class that contains custom events: OnsemendMsg.
File name: ChatServer.cs
Public Class Chat Server
{
Public Delegate Void MyEventHandler (String MSG);
Public evenet myeventhandler oversendmsg;
Public void sendmsg ()
{
Onsendmsg ("Start Send Message!");
}
}
File name: Form1.cs
///
The processing code for // class events is as follows
Private void sendmsgtest ()
{
// Create an instance of a ChatServer class
Server f_server;
f_server = new server ();
f_server.onsendmsg = New Server.MyeventHandler (this.onsendmsg);
// Call the SendMSG () function of F_Server
f_server.sendmsg ();
}
// Handle ONSENDMSG event code
Protected void Onsendmsg (String MSG)
{
// Output debugging information
Console.writeLine (MSG);
}