C # key knowledge detailed (five generations: 2)

zhaozj2021-02-08  206

Guide: Processing 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 overloading in the form class.

Author: wkrain www.ASPCool.com

Two agency

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 agency

I want to deal with 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 event processing, 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 that the number of rotates of the mouse

X mouse click x coordinate point

Y mouse clicking Y coordinate point

Event Handler

Private Void Form_MouseDown (Object Sender, System.winForms 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 idoloveyou ()

{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 Televhone

{public delegate void healthchat ();

Public telephone () {}

~ Televhone () {}

Public void Hello () {System.Console.writeline ("Yesterday Night, I Telephone");}

}

Class chat {

Static void main () {

I i = new i (); Her Her = new Her ();

Televhone Televhone = new telephone ();

Televhone.hello ();

Telephone.heartchat 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-2357.html

New Post(0)