给类添加事件的列子
/// <summary>
/// 事件的参数
/// </summary>
public class BarEventArg:EventArgs
{
public BarEventArg(int li_total,string ls_msg)
{
this.ii_total=li_total;
this.is_msg=ls_msg;
}
private int ii_total;
public int ii_Total
{
get
{
return this.ii_total;
}
set
{
this.ii_total=value;
}
}
private string is_msg;
public string is_Msg
{
get
{
return this.is_Msg;
}
set
{
this.is_msg=value;
}
}
}
/// <summary>
///定义事件的格式
/// </summary>
public delegate void BarEventHandler(BarEventArg e);
public event BarEventHandler BarEvent;
/// <summary>
/// 在类的内部触发事件的格式
/// </summary>
/// <param name="e"></param>
private void StartBarEvent(BarEventArg e)
{
if(this.BarEvent!=null)
{
BarEvent(e);
}
}