【IT168 技术】 C#(C Sharp)是微软(Microsoft)为.NET Framework量身订做的程序语言,C#拥有C/C++的强大功能以及Visual Basic简易使用的特性,是第一个组件导向(Component-oriented)的程序语言,和C++与Java一样亦为对象导向(object-oriented)程序语言。
public class AppEvent{
//键值对委托的形式
public static AppEvent Events = new AppEvents()
private Dictionary DelegateList = new Dictionary();
#region 装备事件索引
public const string Aoi_GeoDraw="aoigeodraw";
#endregion
public void AddListener(string name,EventHandler handler)
{
if(!DelegateList.ContainsKey(name))
{
DelegateList.Add(name,handler);
}
else
{
DelegateList.Remove(name);
DelegateList.Add(name,handler);
}
}
//执行方法
public void Dispath(string name,object obj)
{
if(DelegateList.ContainsKey(name))
{
DelegateList[name](obj,null);
}
}
}
// 窗体调用
// 初始化监听对象
private vid InitalizeEventListener(string list_AoiValue)
{
AppEvent.Events.Dispatch(AppEvent.Aoi_GeoDraw,list_AoiValue);
}
//事件监听
private void InitializeEventListener()
{
AppEvent.Events.AddListener(AppEvent.Aoi_GeoDraw,Aoi_GeoDrawEvent);
}
// 触发事件
private void Aoi_GeoDrawEvent(object sender,EventArgs e)
{
if(sender!=null)
{
txt_Draw=sender.ToString()
}
}
//键值对委托的形式
public static AppEvent Events = new AppEvents()
private Dictionary DelegateList = new Dictionary();
#region 装备事件索引
public const string Aoi_GeoDraw="aoigeodraw";
#endregion
public void AddListener(string name,EventHandler handler)
{
if(!DelegateList.ContainsKey(name))
{
DelegateList.Add(name,handler);
}
else
{
DelegateList.Remove(name);
DelegateList.Add(name,handler);
}
}
//执行方法
public void Dispath(string name,object obj)
{
if(DelegateList.ContainsKey(name))
{
DelegateList[name](obj,null);
}
}
}
// 窗体调用
// 初始化监听对象
private vid InitalizeEventListener(string list_AoiValue)
{
AppEvent.Events.Dispatch(AppEvent.Aoi_GeoDraw,list_AoiValue);
}
//事件监听
private void InitializeEventListener()
{
AppEvent.Events.AddListener(AppEvent.Aoi_GeoDraw,Aoi_GeoDrawEvent);
}
// 触发事件
private void Aoi_GeoDrawEvent(object sender,EventArgs e)
{
if(sender!=null)
{
txt_Draw=sender.ToString()
}
}