C #The message in is retrieved by the Application class from the Application message queue and distributed to the corresponding form of the message. The first response function of the form object is protected override void WndProc (ref System. windows. forms. message e) method.
It then calls the default message response function (such as OnMouseDown) based on the message type, the default response function then according to the event field of the object (such as this. the function pointer list in MouseDown. It calls the user-added response functions (such as Form1_MouseDown1 and Form1_MouseDown2), and the call sequence is the same as the user-added sequence..
According to this process, I have developed an imitation program. If there are any shortcomings, please provide more comprehensive supplements.
Using System;
// Create a delegate, return type void, two parameters
Public delegate void KeyDownEventHandler (object sender, KeyEventArgs e );
// Data parameter class
Class KeyEventArgs: EventArgs
{
Private char keyChar;
Public KeyEventArgs (char keyChar)
: Base ()
{
This. keyChar = keyChar;
}
Public char KeyChar
{
Get {return keyChar ;}
}
}
// Mimic the Application class
Class M_Application
{
Public static void Run (M_Form form)
{
Bool finished = false;
Do
{
Console. WriteLine ("Input a char ");
String response = Console. ReadLine ();
Char responseChar = (response = "")? : Char. ToUpper (response [0]);
Switch (responseChar)
{
Case X:
Finished = true;
Break;
Default:
// Obtain the key information Parameters
KeyEventArgs keyEventArgs = new KeyEventArgs (responseChar );
& N