zoukankan      html  css  js  c++  java
  • 查找所有页面中的按钮

     protected void InitButtons()
            {
                string strSql = "";
                strSql = @"select MFormName  from MenuInfo where SeqNo=@SeqNo";
                DbCommand cmd12 = myGlobal.db.GetSqlStringCommand(strSql);
                myGlobal.db.AddInParameter(cmd12, "@SeqNo", DbType.Int32, 1);
    
                menuInfo = new List<MenuInfo>();
                try
                {
                    using (IDataReader reader = myGlobal.db.ExecuteReader(cmd12))
                    {
                        while (reader.Read())
                        {
                            menuInfo.Add(new MenuInfo()
                            {
                                MFormName = reader["MFormName"].ToString()
                            });
                        }
                    }
                }
                catch
                {
    
                }
    
    
                if (menuInfo != null && menuInfo.Count > 0)
                {
                    IList<ButtonInfo> buttList = new List<ButtonInfo>();
    
                    foreach (MenuInfo m in menuInfo)
                    {
                        BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
                        Assembly asm = Assembly.Load("mytext");
                        Form frm = (Form)asm.CreateInstance(m.MFormName);
                        //frmMeA frm = new frmMeA();
                        FieldInfo[] fields = frm.GetType().GetFields(flag);
    
    
                        foreach (var fi in fields)
                        {
                            if (fi.FieldType == typeof(Button)
                           || fi.FieldType == typeof(SimpleButton))
                            {
                                Control c = fi.GetValue(frm) as Control;
    
                                ButtonInfo bModel = new ButtonInfo();
                                bModel.ButtonType = 1;
                                bModel.ButtonTitle = c.Name;
                                bModel.ButtonPop = c.Text;
                                buttList.Add(bModel);
                            }
                            if (fi.FieldType == typeof(BarButtonItem))
                            {
                                BarButtonItem c = fi.GetValue(frm) as BarButtonItem;
                                if (c != null)
                                {
    
    
                                    ButtonInfo bModel = new ButtonInfo();
                                    bModel.ButtonType = 1;
                                    bModel.ButtonTitle = c.Name;
                                    bModel.ButtonPop = c.Caption;
                                    buttList.Add(bModel);
                                }
                            }
    
                            if (fi.FieldType == typeof(ToolStripMenuItem))
                            {
                                ToolStripMenuItem c = fi.GetValue(frm) as ToolStripMenuItem;
                                if (c != null)
                                {
    
                                    ButtonInfo bModel = new ButtonInfo();
                                    bModel.ButtonType = 1;
                                    bModel.ButtonTitle = c.Name;
                                    bModel.ButtonPop = c.Text;
                                    buttList.Add(bModel);
    
                                }
                            }
                        }
                    }
                    var buttList1 = buttList;
                }
            }
    

      

  • 相关阅读:
    你笑的时候真的很美
    我不会倒下
    创业靠的是“脑子”,教你如何运用谋略事半功倍~
    其实我真的很在乎你
    让你克服低效率的困扰:从实质上迅速提升你生活的方法
    沈科(帮别人名字作诗)
    Secrets of the NetBeans Window System
    PropertyUtils.copyProperties的性能
    Swing Threading的限制
    SwingSet2
  • 原文地址:https://www.cnblogs.com/qufly/p/3445183.html
Copyright © 2011-2022 走看看