zoukankan      html  css  js  c++  java
  • 获得ToolBarButton或MenuItem的(Name)名称,终于搞定

       
         最近用ToolBarButton的Tag关联menuItem的按钮事件,遍历ToolBar时想取得ToolBarButton的名称,找了半天没有搞定,后来用取得整个页面的控件的方法来取得 :)

         //用反射的方法来取得控件的(Name)属性fields[i].Name
        Type t = this.GetType();
        FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

        for (int i = 0; i < fields.Length; i++)
        {
         if (fields[i].FieldType.Name.Equals("ToolBarButton"))
         {
          ToolBarButton toolBarButton = (ToolBarButton) fields[i].GetValue(this);

          //如果需要判断权限(只能根据TAG来判断,故需要设置TAG的值为NAME)
          if (toolBarButton.Visible == true && toolBarButton.Tag != null)
          {
           strControlTag = fields[i].Name.ToUpper();
            }
         }
        }

        不知是否有兄台有更好的方法,还请告知小弟..

    非有希望才坚持,坚持才会有希望
  • 相关阅读:
    HDU-1527 取石子游戏
    HDU-1846 Brave Game
    HDU-1850 Being a Good Boy in Spring Festival
    HDU-2509 Be the Winner
    HDU-1907 John
    HDU-1969 Pie
    HDU-1501 Zipper
    HDU-2289 Cup
    最大子矩阵和
    HDU3466(01背包变种)
  • 原文地址:https://www.cnblogs.com/eugenewu0808/p/GetToolBarButton.html
Copyright © 2011-2022 走看看