public class AppEvent{
//键值对委托的形式
public static AppEvent Events = new AppEvents()
private Dictionary<string, EventHandler> DelegateList = new Dictionary<string ,EventHandler>();
#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()
}
}