using System;
namespace TestEventArgs
{
/// <summary>
/// 这个类对应于EventArgs,做对比学习。
/// 添加两个内容:info1,info2。
/// </summary>
public class MyEventArgs : EventArgs
{
private String info1;
private UInt32 info2;
public MyEventArgs(String info1, UInt32 info2)
{
this.info1 = info1;
this.info2 = info2;
}
public String Info1
{
get { return this.info1; }
set { this.info1 = value; }
}
public UInt32 Info2
{
get { return this.info2; }
set { this.info2 = value; }
}
}
/// <summary>
/// 仿真Button按钮
/// </summary>
public class MyButton
{
public delegate void MyEvnetHandler(object sender, MyEventArgs e);
/// <summary>
/// 按钮点击的次数计数器
/// </summary>
public static UInt32 clicked_num = 0;
public event MyEvnetHandler MyClick;
public void 触发()
{
MyEventArgs arg = new MyEventArgs(DateTime.UtcNow.ToString(), ++clicked_num);
MyClick(this, arg);
}
}
/// <summary>
/// 仿真Form窗体
/// </summary>
public class MyForm
{
public MyButton 按钮;
public MyForm()
{
按钮 = new MyButton();
按钮.MyClick += new MyButton.MyEvnetHandler(this.button_Clicked);
}
public void button_Clicked(object sender, MyEventArgs e)
{
Console.WriteLine("button clicked(sender is:" + sender.ToString() + "; info1 = "
+ e.Info1 + "; info2 = " + e.Info2);
}
}
class Program
{
static void Main(string[] args)
{
MyForm 窗体 = new MyForm();
for (int i = 0; i < 10; i++ )
{
窗体.按钮.触发();
System.Threading.Thread.Sleep(500);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有