C # Key knowledge detailed (five generations)

zhaozj2021-02-11  185

Two agency

Mood is so bad !!!!!!!!!!!!!!!!!!!!! My quasi-boyfriend tells me !!!!!!!!!!!!!!!!!! !!! Never want to engage in computer brothers retreat !!!!!!!!!!!!!!!!!!!! C # I didn't have a mood. Let's talk later !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

1> Event

The previous chapter explains the basic application of the agent, which will continue to explain the use of in-depth agents. Here we explain the use of agents to handle events. About the event detailed explanation in another chapter. Treatment events are smarter in C and VBs, you can write a proxy and write event handlers, and event handlers are a public event defined in the control and overloaded in the form class. We will see the application in the event in the following examples.

1. Write a proxy I want to handle the mouse click the event and click the left button or right click on the mouse. Write the following code in your initial control function.

THIS.MOUSEDOWN = New System.winForms.MouseEventHandler (this.form_mousedown);

2. Write an event Now you can write an event process, and your event's output parameters will return the details of the mouse event parameters of the form. Mouse event parameters member

MouseEventargs Members

Button indicates which key is pressed, divided into left, right, medium, no. ClickS indicates the number of mouse pressure and the release state. Delta indicates the number of mouse rotations count x mouse click X coordinate point y mouse click Y Y coordinate point

Event Handler

private void Form_MouseDown (object sender, System.WinForms.MouseEventArgs e) {switch (e.Button) {case MouseButtons.Left: MessageBox.Show (this, "Left Button Click"); break; case MouseButtons.Right: MessageBox.Show (This, "Right Button Click"; Break; Case MouseButtons.Middle: Break; Default: Break;}

}

Test your program in your WinForm, you will see that the proxy event is associated.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Class i {public i () {} ~ i ()} public void IDOLOVEOUVEYOU () {System.Console.writeLine ("I do love you");

Public void why () {system.console.writeline ("why?");}}

Class Her {public her () {} ~ Her () {} public void IDO () {system.console.writeline (".............");} public void slient () {System.console.writeline (".........");}}

class TELEPHONE {public delegate void heartchat (); public TELEPHONE () {} ~ TELEPHONE () {} public void hello () {System.Console.WriteLine ( "yesterday night, i telephone to my girlfriend");}}

Class chat {static void main () {i = new i (); he her = new her (); telephone telephone = new telephone (); telephone.hert tell = new telephone.heartchat (i .Idoloveyou); Tell ();

TELEPHONE.heartchat answer = new TELEPHONE.heartchat (her.IDo); answer (); TELEPHONE.heartchat ask = new TELEPHONE.heartchat (i.why); ask (); TELEPHONE.heartchat noanswer = new TELEPHONE.heartchat (her. Slient; Noanswer ();}}

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

New Post(0)