private void btnOK_Click(object sender, EventArgs e) { int row = 1; for (int i = Groups.Count - 1; i >= 0; i--) { string group = Groups[i]; ExpandingPanel panel = pnlMain.Controls["panel" + i.ToString()] as ExpandingPanel; if (panel == null) { return; } List <IProperty> attr = getAttributes(group); for (int j = attr.Count - 1; j >= 0; j--) { IProperty pa = attr[j]; string name = ""; if (pa.Range != null) { name = "Combo" + row.ToString(); } else { name = "Textbox" + row.ToString(); } if (name != "") { Control ctrl = panel.Controls[name]; if (ctrl != null) { pa.Value = ctrl.Text; } } //if (name != "") row++; } //for (int j = attr.Count - 1; j >= 0; j--) } //for (int i = Groups.Count - 1; i >= 0; i--) } //private void btnOK_Click(object sender, EventArgs e)
private void InitializeForm() { if (ConnectionProperties.Count > 0) { Graphics g = Graphics.FromHwnd(Handle); int caption = 0; int row = 1; Groups = new List <string>(); foreach (IProperty pa in ConnectionProperties) { if (!Groups.Contains(pa.Group)) { Groups.Add(pa.Group); } caption = Math.Max(caption, g.MeasureString(pa.Caption, pnlMain.Font).ToSize().Width); } for (int i = Groups.Count - 1; i >= 0; i--) { string group = Groups[i]; ExpandingPanel panel = new ExpandingPanel(); panel.Name = "panel" + i.ToString(); panel.Text = group; panel.Dock = DockStyle.Top; pnlMain.Controls.Add(panel); List <IProperty> attr = getAttributes(group); int xOffs = 20; int yOffs = panel.TopHeight + 10; for (int j = attr.Count - 1; j >= 0; j--) { IProperty pa = attr[j]; if ((pa.AttributeRequirement & eAttributeRequirement.Mandatory) == eAttributeRequirement.Mandatory) { PictureBox pic = new PictureBox(); pic.Name = "PictureBox" + row.ToString(); pic.Left = 2; pic.Top = yOffs;// - 4; pic.Width = 16; pic.Height = 20; pic.SizeMode = PictureBoxSizeMode.Zoom; pic.Image = imageList1.Images[0]; panel.Controls.Add(pic); } Label lbl = new Label(); lbl.Name = "Label" + row.ToString(); lbl.Text = pa.Caption; lbl.Left = xOffs; lbl.Top = yOffs; //lbl.Width = caption; lbl.Height = 20; lbl.Font = pnlMain.Font; panel.Controls.Add(lbl); if (pa.Range != null) { ComboBox cb = new ComboBox(); cb.Name = "Combo" + row.ToString(); cb.Items.AddRange(pa.Range); cb.Text = pa.Value; cb.Top = yOffs; cb.Height = 20; cb.Left = xOffs + caption + 10; cb.Width = panel.Width - (cb.Left + 10); cb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; cb.Enabled = (pa.AttributeRequirement & eAttributeRequirement.User) == eAttributeRequirement.User; panel.Controls.Add(cb); if (pa.Tooltip != "") { toolTip1.SetToolTip(cb, pa.Tooltip); } AttributeControlMapping.Add(pa, cb); } //if (pa.Range != null) else { TextBox tb = new TextBox(); tb.Name = "Textbox" + row.ToString(); tb.Text = pa.Value; tb.Top = yOffs; tb.Height = 20; tb.Left = xOffs + caption + 10; tb.Width = panel.Width - (tb.Left + 10); tb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; tb.Enabled = (pa.AttributeRequirement & eAttributeRequirement.User) == eAttributeRequirement.User; if ((pa.AttributeRequirement & eAttributeRequirement.Password) == eAttributeRequirement.Password) { tb.PasswordChar = PasswordChar; } tb.MouseDown += Tb_MouseDown; panel.Controls.Add(tb); if (pa.Tooltip != "") { toolTip1.SetToolTip(tb, pa.Tooltip); } AttributeControlMapping.Add(pa, tb); if (pa.AttributeDomainType == eAttributeDomainType.FileOrPath) { tb.Width -= 30; Button btn = new Button(); btn.Name = "Button" + row.ToString(); btn.Tag = pa; btn.Text = "..."; btn.Click += new EventHandler(btn_Click); btn.Top = yOffs; btn.Height = 20; btn.Left = panel.Width - 30; btn.Width = 20; btn.Anchor = AnchorStyles.Top | AnchorStyles.Right; btn.Enabled = (pa.AttributeRequirement & eAttributeRequirement.User) == eAttributeRequirement.User; panel.Controls.Add(btn); } //if (pa.PersoAttributeDomainType == PersoAttributeDomainType.FileOrPath) } //else, if (pa.Range != null) yOffs += 35; row++; } //for (int j = attr.Count - 1; j >= 0; j--) panel.ExpandedHeight = panel.Height = yOffs; Panel splitter = new Panel(); splitter.Name = "splitter" + i.ToString(); splitter.BackColor = Color.DarkGray; splitter.Height = 2; splitter.Dock = DockStyle.Top; pnlMain.Controls.Add(splitter); } //for(int i = Groups.Count - 1; i >= 0; i--) } //if (_PersoDevice != null) } //private void InitializeForm()