事件的参数

private void Button3_Click(object sender, System.EventArgs e)

一般来说,事件的相应方法会有两个参数,

参数:object sender

其中一个代表引发事件的对象即sender。由于引发事件的对象是不可知的,因此我们把其声明为object类型。所有对象都适用。

Button s = (Button)sender;

       string a = s.Text;

参数:EventArgs

第二个参数代表引发事件的具体信息。下面是MSDN对这个类的描述

This class contains no event data; it is used by events that do not pass state information to an event handler when an event is raised. If the event handler requires state information, the application must derive a class from this class to hold the data

各种事件中的类型可能不同。但是都是从EventArgs继承而来。例如

DataGridItemEventArgs

The ItemCreated event is raised when an item in the DataGrid control is created.

The ItemDataBound event is raised when an item in the DataGrid control is data bound to a source.

事件的定义

如何定义事件:

[attributes] [modifiers] event type declarator;

type

The delegate to which you want to associate this event.

例如:public event MyDelegate MyEvent;