public static IEnumerable <Control> Iterate(this Control.ControlCollection self) { foreach (var node in self.Cast <Control>()) { foreach (var internalNode in Iterate(node.Controls)) { yield return(internalNode); } yield return(node); } }
/** * \brief This function listener for button click events * \param kontroller */ public static void AttachButton(Control.ControlCollection kontroller) { foreach (var item in kontroller.Cast <Control>()) { if (item is Button) { Button btn = (Button)item; btn.Click += SaveLog; } else { AttachButton(item.Controls); } } }
public void Test_AddMappersByConventions_WhenCheckBox_WhenUsesConvention_ShouldAddCheckBoxMapper_WithCorrectControlAndProperty() { //---------------Set up test pack------------------- var haberoControlBinder = CreateHabaneroControlBinder(); var checkBox = new CheckBox { Name = "chkFakeBoolProp" }; Control.ControlCollection controls = GetControlsCollection(checkBox); //---------------Assert Precondition---------------- Assert.AreEqual(1, controls.Count, "Should have CheckBox"); Assert.Contains(checkBox, controls, "Should have CheckBox"); Assert.AreEqual(0, haberoControlBinder.ControlMappers.Count); //---------------Execute Test ---------------------- haberoControlBinder.AddMappersByConvention(controls.Cast<Control>()); //---------------Test Result ----------------------- Assert.AreEqual(1, haberoControlBinder.ControlMappers.Count); var checkBoxMapper = haberoControlBinder.ControlMappers[0]; var checkBoxAdapter = checkBoxMapper.Control as IWinFormsCheckBoxAdapter; Assert.IsNotNull(checkBoxAdapter, "Should adapt the winforms control"); Assert.AreSame(checkBox, checkBoxAdapter.WrappedControl); Assert.AreEqual("FakeBoolProp", checkBoxMapper.PropertyName, "The prop name should be derived from the control.Name"); }
public static void Validate(this Control.ControlCollection controls, Control.ControlCollection controlsToIgnore) { if (controls == null || controls.Count == 0) { return; } var controlsConverted = controls.Cast <Control>().Where(a => controlsToIgnore != null ? !controlsToIgnore.Contains(a) : true).OrderBy(a => a.TabIndex).ToList <Control>(); foreach (var control in controlsConverted) { if (control.Controls.Count > 0) { control.Controls.Validate(); } if (control is CButtonEdit) { (control as CButtonEdit).Validate(); } else if (control is CComboBoxEdit) { (control as CComboBoxEdit).Validate(); } else if (control is CTextEdit) { (control as CTextEdit).Validate(); } else if (control is CMemoEdit) { (control as CMemoEdit).Validate(); } else if (control is CSpinEdit) { (control as CSpinEdit).Validate(); } } }
/// <summary> /// Returns the control collection as an array of controls. /// </summary> /// <param name="controlCollection">The control collection.</param> /// <returns>An array of controls contained within the collection.</returns> public static Control[] ToArray(this Control.ControlCollection controlCollection) { return(controlCollection.Cast <Control>().ToArray()); }
/// <summary> /// Recursively gets all WinForms controls. /// </summary> public static IEnumerable <Control> GetRecursive(this Control.ControlCollection collection) { return(collection.Cast <Control>().Flatten(c => c.Controls.Cast <Control>())); }
public void ValidateAll(Control.ControlCollection ctls) { try { foreach (Control ctl in ctls.Cast <Control>().OrderBy(c => c.TabIndex)) { if (ctl.HasChildren) { ValidateAll(ctl.Controls); } if (ctl.Tag != null) { //Datatype validation if (((SQLTag)ctl.Tag).DBType.ToString() == "Number") { if (ctl.Text != "") { if (!ctl.GetType().ToString().Contains("ComboBox")) { if (!gs.IsNumeric(ctl.Text)) { SetWarningLabel(ctls, ((SQLTag)ctl.Tag).LabelName); } } } else { ctl.Text = "0"; } } if (((SQLTag)ctl.Tag).DBType.ToString() == "NumberNotZero") { if (ctl.Text != "") { if (!ctl.GetType().ToString().Contains("ComboBox")) { if (!gs.IsNotZero(ctl.Text)) { SetWarningLabel(ctls, ((SQLTag)ctl.Tag).LabelName); } } } else { SetWarningLabel(ctls, ((SQLTag)ctl.Tag).LabelName); } } //Mandatory field validation if (((SQLTag)ctl.Tag).Mandatory == "Y") { //MessageBox.Show("Mandatory: " + ctl.Name); if (ctl.Text == "") { SetWarningLabel(ctls, ((SQLTag)ctl.Tag).LabelName); } } } } } catch { } }
public Control Validate(Control.ControlCollection ctls) { if (CtlToValidate != null) { return(CtlToValidate); } try { foreach (Control ctl in ctls.Cast <Control>().OrderBy(c => c.TabIndex)) { //if (ctl.Name == "cbStockCategory") //{ // MessageBox.Show(ctl.Name); //} if (ctl.HasChildren) { Validate(ctl.Controls); } if (ctl.Tag != null) { //Datatype validation if (((SQLTag)ctl.Tag).DBType.ToString() == "Number") { // MessageBox.Show("Number: " + ctl.Name); if (ctl.Text != "") { if (!ctl.GetType().ToString().Contains("ComboBox")) { if (!gs.IsNumeric(ctl.Text)) { return(CtlToValidate = ctl); } } } else { ctl.Text = "0"; } } if (((SQLTag)ctl.Tag).DBType.ToString() == "NumberNotZero") { // MessageBox.Show("Number: " + ctl.Name); if (ctl.Text != "") { if (!ctl.GetType().ToString().Contains("ComboBox")) { if (!gs.IsNotZero(ctl.Text)) { return(CtlToValidate = ctl); } } } else { return(CtlToValidate = ctl); } } if (((SQLTag)ctl.Tag).DBType.ToString() == "Text") { //MessageBox.Show("Text: " + ctl.Name); if (ctl is TextBox) { if (ctl.Text != "") { ctl.Text = gs.SafeString(ctl.Text); } } } //Mandatory field validation if (((SQLTag)ctl.Tag).Mandatory == "Y") { //MessageBox.Show("Mandatory: " + ctl.Name); if (ctl.Text == "") { return(CtlToValidate = ctl); } } } } } catch { } return(CtlToValidate); }
public void SetLayout(Control.ControlCollection controls) { SetLayout(controls.Cast <Control>()); }
public static bool ValidateInput(this Control.ControlCollection controlCollection, ErrorProvider errorProvider) { return(controlCollection.Cast <Control>().Aggregate(true, (current, control) => ValidateInputValue(control, errorProvider, current))); }
private void InitializeCustomInputs(Control.ControlCollection ctrls) { LogHelper.Write(LogWriterLevel.FUNCTIONS, LogWriterIO.START); LogHelper.Write(LogWriterLevel.PARAMETERS, "Controls count: " + ctrls.Count); ctrls.Cast <Control>().ToList().ForEach(ctrl => { LogHelper.Write(LogWriterLevel.PARAMETERS, "Control[" + ctrls.IndexOf(ctrl).ToString().PadLeft(ctrls.Count.ToString().Length, '0') + "].Name: " + ctrl.Name); if (ctrl.Tag != null && ctrl.Tag.ToString().Contains("#container#")) { if (ctrl.Tag.ToString().Contains("#text#")) { ctrl.BackColor = frmMain.colorCustomTextColorLeave; var ppnl = (Panel)ctrl.Controls[0]; var ctxt = ppnl.Controls.OfType <TextBox>().Single(); // // root/parent :: panel => border // ctrl.MouseEnter /**/ += (s, e) => ctrl.BackColor = frmMain.colorCustomTextColorEnter; ctrl.MouseLeave /**/ += (s, e) => ctrl.BackColor = ctxt.Focused ? frmMain.colorCustomTextColorEnter : frmMain.colorCustomTextColorLeave; ctrl.Click /**/ += (s, e) => ctxt.Focus(); // // parent.child :: panel => padding // ppnl.MouseEnter /**/ += (s, e) => ctrl.BackColor = frmMain.colorCustomTextColorEnter; ppnl.MouseLeave /**/ += (s, e) => ctrl.BackColor = ctxt.Focused ? frmMain.colorCustomTextColorEnter : frmMain.colorCustomTextColorLeave; ppnl.Click /**/ += (s, e) => ctxt.Focus(); // // parent.parent.child :: textbox => input // ctxt.GotFocus /**/ += (s, e) => ctrl.BackColor = frmMain.colorCustomTextColorEnter; ctxt.LostFocus /**/ += (s, e) => ctrl.BackColor = frmMain.colorCustomTextColorLeave; ctxt.MouseEnter /**/ += (s, e) => ctrl.BackColor = frmMain.colorCustomTextColorEnter; ctxt.MouseLeave /**/ += (s, e) => ctrl.BackColor = ((Control)s).Focused ? frmMain.colorCustomTextColorEnter : frmMain.colorCustomTextColorLeave; if (ctrl.Tag.ToString().Contains("#check.path#")) { var cpic = ppnl.Controls.OfType <PictureBox>().Single(); ctxt.TextChanged += (s, e) => { if (ctxt.Text.Trim().Length == 0) { cpic.Image = global::AnimeExtractor.Properties.Resources.png_circle_cross; this.toolTip1.SetToolTip(cpic, "this field is required"); } else if (!Directory.Exists(ctxt.Text)) { cpic.Image = global::AnimeExtractor.Properties.Resources.png_circle_cross; this.toolTip1.SetToolTip(cpic, "directory not found"); } else { cpic.Image = global::AnimeExtractor.Properties.Resources.png_circle_check; this.toolTip1.SetToolTip(cpic, "okay"); } }; } } } else if (ctrl.Controls.Count > 0) { LogHelper.Write(LogWriterLevel.FUNCTIONS, "InitializeCustomInputs from " + ctrl.Name); InitializeCustomInputs(ctrl.Controls); } }); LogHelper.Write(LogWriterLevel.FUNCTIONS, LogWriterIO.CLOSE); }
public static IEnumerable <Control> AsEnumerable(this Control.ControlCollection collection) { return(collection.Cast <Control>().AsEnumerable()); }
public static List <Control> ToList(this Control.ControlCollection controls) { return(controls.Cast <Control>().ToList()); }