事件的參數(shù)
private void Button3_Click(object sender, System.EventArgs e)
一般來說,事件的相應(yīng)方法會(huì)有兩個(gè)參數(shù),
參數(shù):object sender
其中一個(gè)代表引發(fā)事件的對(duì)象即sender。由于引發(fā)事件的對(duì)象是不可知的,因此我們把其聲明為object類型。所有對(duì)象都適用。
Button s = (Button)sender;
string a = s.Text;
參數(shù):EventArgs
第二個(gè)參數(shù)代表引發(fā)事件的具體信息。下面是MSDN對(duì)這個(gè)類的描述
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;