Connected to one: C # event mechanism for induction (I)
3. C # in the pre-defined event handling
Learning event, I think the most difficult to understand is that C # in the predefined event, so I began to study events at a loss. In search of more information, finally got a number of, as follows:
EventArgs that contains event data of the type of the base class for the transfer of the incident.
EventHandler is a delegate declared as follows (in. Net class library in the following statement)
public delegate void EventHandler (object sender, EventArgs e)
Therefore, all of the form:
Lou void letter name (object parameter name, EventArgs parameter name); the function can be used as the Click event to respond to Control class methods. Defined as an event the following response method:
private void button1_Click (object sender, System.EventArgs e)
Parameter object sender object that triggered the event, (in fact there is a reference to the object passed, if the sender button1's click event is button1) System.EventArgs e on behalf of the corresponding event information, such as the mouse's x, y values and so on.
Now we look to see which events Button class declaration to Click Event.
public event EventHandler Click;
Here defines a type of event EventHandler Click
private void button1_Click (object sender, System.EventArgs e)
(
...
)
This is what we and the corresponding method button1_click events. Note that the parameters meet the commission in the method signature (parameters both list). Then how do we put this method and events linked to it, see the following code.
this.button1.Click + = new System.EventHandler (this.button1_Click); (actually button1.Click System.EventHandler delegate to an instance of the event. and appoint the commission assigned to a particular instance of the method is very similar)
The this.button1_Click method bound to this.button1.Click event.
4. The use of the parameters of the incident.
using System;
class Class1
(
static void Main ()
(
Student s1 = new Student ();
s1.Name = "Student1";
Student s2 = new Student ();
s2.Name = "Student2";
s1.RegisterOK + = new Student.DelegateRegisterOkEvent (Student_RegisterOK);
s2.RegisterOK + = new Student.DelegateRegisterOkEvent (Student_RegisterOK);
/ / When the Register method of an execution, the event triggered RegisterOK
/ / RegisterOK event of a trigger, then perform Student_RegisterOK method
s1.Register ();
s2.Register ();
Console.ReadLine ();
)
static void Student_RegisterOK (RegisterOkArgs e)
(
Console.WriteLine (e.EventInfo);
)
)
class Student
(
public delegate void DelegateRegisterOkEvent (RegisterOkArgs e);
public event DelegateRegisterOkEvent RegisterOK;
public string Name;
public void Register ()
(
Console.WriteLine ("Register Method");
RegisterOK (new RegisterOkArgs ("Student Name:" + Name));
)
)
class RegisterOkArgs: EventArgs
(
public string EventInfo;
public RegisterOkArgs (string eventInfo): base ()
(
this.EventInfo = eventInfo;
)
)
Recommended links:
C # in the DELEGATE and event
WMV To QT
Dealers Sustained Growth Quartet
"China Computer Business 500" award, awarded the two winning BenQ chase THE deer
Simple Flash Tools
COMMENT Launchers And Task Managers
SCO UNIX Learning Collection
MPEG To 3GPP
Simple Business
Compilation of the stack of parameters passed and amended
Programming books from the ENTER_FRAME ActionScript3 Speaking
Deep Antivirus Guide (1)
AVI to MOV
Png files
IP And MAC Binding Of Crack
Charles Zhang said Sohu Sogou do NOT intend to use the input method earnings
Its like you learn my thoughts! You seem to know
ReplyDeleteso much about this, such as you wrote the book in it or something.
I believe that you just could do with a few % to drive the message house a little bit, but instead of
that, that is excellent blog. A great read. I'll certainly be
back.
Also visit my web site: magnetic messaging pdf