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()

     }

}

相关文章:

  • 2021-07-16
  • 2021-09-20
  • 2022-01-11
  • 2021-08-21
  • 2021-06-02
猜你喜欢
  • 2022-03-11
  • 2021-07-16
  • 2021-12-21
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-03-03
相关资源
相似解决方案