public void SetTextBox(TextBoxDropDown txt) { this.txt = txt; this.txt.DropDownControl = this.chkBox; this.otherValues.Clear(); //Find values do not exist in the CheckedListBox.Items Dictionary <string, int> items = new Dictionary <string, int>(); for (int i = 0; i < this.chkBox.Items.Count; i++) { object obj = this.chkBox.Items[i]; items.Add(obj.ToString().Trim(), i); this.chkBox.SetItemChecked(i, false); } if (!string.IsNullOrEmpty(this.txt.Text.Trim())) { string[] values = this.txt.Text.Split(new char[] { ',' }); foreach (string str in values) { if (!string.IsNullOrEmpty(str.Trim())) { if (!items.ContainsKey(str.Trim())) { this.otherValues.Add(str.Trim()); } else //有比對到,則 ckeck this item { this.chkBox.SetItemChecked(items[str.Trim()], true); } } } // end foreach } // end if }
public static void BindDataSource(string key, TextBoxDropDown cbx, MethodInvoker callback = null) { cbx.AutoCompleteCustomSource.AddRange(DataSourceByKey(key).ToArray()); foreach (var s in DataSourceByKey(key)) { ButtonItem bi = new ButtonItem("", s); bi.Click += delegate { cbx.Text = bi.Text; if (callback != null) { callback(); } }; cbx.DropDownItems.Add(bi); } }
public void SetControlsText(Control ctrl) { SetControlText(ctrl); foreach (Control c in ctrl.Controls) { if (c is TextBoxDropDown) { TextBoxDropDown tbdd = c as TextBoxDropDown; foreach (BaseItem bi in tbdd.DropDownItems) { SetBaseItemText(bi); } } else if (c is ContextMenuBar) { ContextMenuBar cmb = c as ContextMenuBar; foreach (BaseItem bi in cmb.Items) { SetBaseItemText(bi); } } else if (c is MetroStatusBar) { MetroStatusBar msb = c as MetroStatusBar; foreach (BaseItem bi in msb.Items) { SetBaseItemText(bi); } } else { SetControlText(c); } if (c.HasChildren) { SetControlsText(c); } } }
public StudABCard_YearlyForm_TextDropDown(UDTYearlyDataDef data) { InitializeComponent(); _data = data; _TextBoxDropDownDic = new Dictionary <string, TextBoxDropDown>(); foreach (Control cr in this.panelEx1.Controls) { if (cr is TextBoxDropDown) { TextBoxDropDown dd = cr as TextBoxDropDown; _TextBoxDropDownDic.Add(cr.Name, dd); } } foreach (string key in _TextBoxDropDownDic.Keys) { CheckedListBox itm = new CheckedListBox(); itm.Name = key; itm.LostFocus += new EventHandler(itm_LostFocus); _CheckList.Add(itm); } }
private Control createTextBoxDropDown(Question q) { int innerPanelLength = 0; FlowLayoutPanel pnlInner = new FlowLayoutPanel(); pnlInner.FlowDirection = FlowDirection.LeftToRight; pnlInner.Width = 120; //pnl.BackColor = System.Drawing.Color.Green; Label lbl = this.createLabel(q.GetQuestionLabel()); pnlInner.Controls.Add(lbl); innerPanelLength += lbl.Width + 6; TextBoxDropDown txt = new TextBoxDropDown(); txt.Enabled = false; txt.Name = q.GetQuestionName(); txt.DropDownControl = this.getDropDownControl(q); txt.ButtonDropDown.Text = "..."; txt.ButtonDropDown.Visible = true; txt.Width = 150; txt.Height = 20; txt.TextAlign = HorizontalAlignment.Left; txt.Tag = q; txt.TextChanged += new EventHandler(txt_TextChanged); txt.ButtonDropDownClick += new System.ComponentModel.CancelEventHandler(txt_ButtonDropDownClick); //調整寬度 pnlInner.Width = innerPanelLength + txt.Width + 6; if (!string.IsNullOrEmpty(q.GetWidth())) { if (q.GetWidth().ToUpper() == "FILL") { pnlInner.Width = this.contentPanel.Width - 12; txt.Width = pnlInner.Width - innerPanelLength - 12; } else { int width = 0; bool isnum = int.TryParse(q.GetWidth(), out width); if (isnum) { txt.Width = width; pnlInner.Width = innerPanelLength + txt.Width + 6; } } } //txt.Text = q.GetQuestionName(); pnlInner.Controls.Add(txt); this.allQControls.Add(txt.Name, txt); //pnlInner.Width = innerPanelLength + txt.Width + 6; pnlInner.Height = txt.Height + 6; //adjust height int periodCount = 4; this.contentPanel.Height = 6 + 20 * ((this.questionGroup.GetQuestions().Count % periodCount == 0) ? (this.questionGroup.GetQuestions().Count / periodCount + 1) : (this.questionGroup.GetListItems().Count / periodCount + 2)); this.pnlQGroup.Height = this.contentPanel.Height + 6; return(pnlInner); }