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(); 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 buttList = new List (); 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; } }