private void FrmColumns_Load(object sender, EventArgs e) { int LocationY = 40; foreach (MColumnStyle columnStyle in m_List) { //创建CheckBox控件 TXCheckBox myCheckBox = CreateCheckBox(columnStyle); myCheckBox.Location = new Point(this.Width / 2 - myCheckBox.Width / 2, LocationY); this.Controls.Add(myCheckBox); LocationY += 30; } }
/// <summary> /// 获取显示的归档列表 /// </summary> private void CreateCheckBokList() { IList <MDL.T_GdList> gd_list = (new BLL.T_GdList_BLL()).FindByProjectNo(Globals.ProjectNO); TXCheckBox ckb_gd = null; Point p = new Point(); p.X = 30; for (int i = 0; i < gd_list.Count; i++) { MDL.T_GdList gd_mdl = gd_list[i]; if (gd_mdl.IsShow == 0) { gd_list.Remove(gd_mdl); i--; continue; } if (i > 0 && i % 7 == 0) { p.X += 247; p.Y = 15; } else { if (i == 0) { p.Y = 15; } else { p.Y += 40; } } ckb_gd = new TXCheckBox(); ckb_gd.Name = gd_mdl.ID; ckb_gd.Text = gd_mdl.GdName; ckb_gd.Location = p; if (string.Compare(ckb_gd.Name, _gdID) == 0) { ckb_gd.Checked = true; } this.pl_gd.Controls.Add(ckb_gd); ckb_gd.CheckedChanged += new EventHandler(this.CheckBox_CheckedChanged); } }
/// <summary> /// 创建CheckBox /// </summary> /// <param name="columnStyle"></param> private TXCheckBox CreateCheckBox(MColumnStyle columnStyle) { TXCheckBox myCheckBox = new TXCheckBox(); myCheckBox.BackColor = Color.Transparent; myCheckBox.Text = columnStyle.ColumnCaption; if (columnStyle.ColumnVisible == 1) { myCheckBox.Checked = true; } else { myCheckBox.Checked = false; } myCheckBox.Tag = columnStyle; return(myCheckBox); }
//保存 private void txButton1_Click(object sender, EventArgs e) { try { foreach (Control control in this.Controls) { TXCheckBox myCheckBox = control as TXCheckBox; if (myCheckBox == null) { continue; } MColumnStyle mColumnStyle = myCheckBox.Tag as MColumnStyle; if (mColumnStyle == null) { continue; } int visible = 0; if (myCheckBox.Checked) { visible = 1; } else { visible = 0; } if (visible != mColumnStyle.ColumnVisible) { mColumnStyle.ColumnVisible = visible; m_ColumnStyleBLL.Update(mColumnStyle); } } this.Info("保存成功!"); this.Close(); } catch (Exception ex) { this.Warning(ex.Message); } }