private string GetUserInput(Data_Types d) { switch (d) { case Data_Types.BOOL: { return cb.Checked.ToString(); } case Data_Types.LIST: if (String.IsNullOrEmpty(cmbo.Text)) { MessageBox.Show("Please select a vaule!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return null; } return cmbo.Text; case Data_Types.STRING: if (String.IsNullOrEmpty(tbx.Text)) { MessageBox.Show("Please enter a vaule!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return null; } return tbx.Text; case Data_Types.BYTE: case Data_Types.DECIMAL: case Data_Types.INTEGER: case Data_Types.SHORT: { return Numeric.Value.ToString(); } default: { return string.Empty; } } }
private void AddDynamicInputControl(Data_Types d, string FriendlyName, List<string> OptionList, string PrefilledValue = null) { switch (d) { case Data_Types.NONE: panelUserInputControls.Controls.Clear(); break; case Data_Types.BOOL: panelUserInputControls.Controls.Clear(); cb.Text = FriendlyName; panelUserInputControls.Controls.Add(cb); if (PrefilledValue != null) { bool bvalue = false; bool.TryParse(PrefilledValue, out bvalue); cb.Checked = bvalue; } break; case Data_Types.LIST: panelUserInputControls.Controls.Clear(); cmbo.DropDownStyle = ComboBoxStyle.DropDownList; cmbo.DataSource = OptionList; // if (cmbo.Items.Count > 0) // cmbo.SelectedIndex = 0; if (PrefilledValue != null) cmbo.Text = PrefilledValue; panelUserInputControls.Controls.Add(cmbo); break; case Data_Types.STRING: panelUserInputControls.Controls.Clear(); panelUserInputControls.Controls.Add(tbx); if (PrefilledValue != null) { tbx.SelectedText = PrefilledValue; } break; case Data_Types.INTEGER: panelUserInputControls.Controls.Clear(); Numeric.Maximum = Int64.MaxValue; Numeric.Minimum = Int64.MinValue; panelUserInputControls.Controls.Add(Numeric); if (PrefilledValue != null) { int ivalue = 0; int.TryParse(PrefilledValue, out ivalue); Numeric.Value = ivalue; } break; case Data_Types.BYTE: panelUserInputControls.Controls.Clear(); Numeric.Maximum = Byte.MaxValue; Numeric.Minimum = Byte.MinValue; panelUserInputControls.Controls.Add(Numeric); if (PrefilledValue != null) { byte bvalue = 0; byte.TryParse(PrefilledValue, out bvalue); Numeric.Value = bvalue; } break; case Data_Types.DECIMAL: panelUserInputControls.Controls.Clear(); Numeric.Maximum = Decimal.MaxValue; Numeric.Minimum = Decimal.MinValue; panelUserInputControls.Controls.Add(Numeric); if (PrefilledValue != null) { decimal dvalue = 0; decimal.TryParse(PrefilledValue, out dvalue); Numeric.Value = dvalue; } break; } }
public static int DrawDynamicUserInputBoxes(Panel p, Data_Types paramType, int top, int left, string UniqueName, string CommandText, List<string> options, string value, object tag ) { NumericUpDown Numeric = new NumericUpDown(); switch ((Data_Types)paramType) { case Data_Types.NONE: return left; case Data_Types.BOOL: CheckBox cb = new CheckBox(); cb.Name = UniqueName; cb.Text = CommandText; cb.Top = top + 3; cb.Left = left + 3; cb.Tag = tag; p.Controls.Add(cb); cb.AutoSize = true; if (!String.IsNullOrEmpty(value)) { bool bval = true; bool.TryParse(value, out bval); cb.Checked = bval; } left += cb.Width + 5; break; case Data_Types.DECIMAL: Numeric.Name = UniqueName; Numeric.Top = top; Numeric.Width = 175; Numeric.Left = left; Numeric.Tag = tag; Numeric.DecimalPlaces = 11; Numeric.Maximum = Decimal.MaxValue; Numeric.Minimum = Decimal.MinValue; p.Controls.Add(Numeric); left += Numeric.Width + 5; if (!String.IsNullOrEmpty(value)) { Decimal dec = 0; Decimal.TryParse(value, out dec); Numeric.Value = dec; } break; case Data_Types.BYTE: Numeric.Name = UniqueName; Numeric.Top = top; Numeric.Left = left; Numeric.Tag = tag; Numeric.Maximum = Byte.MaxValue; Numeric.Minimum = Byte.MinValue; Numeric.Width = 50; p.Controls.Add(Numeric); left += Numeric.Width + 5; if (!String.IsNullOrEmpty(value)) { Byte b = 0; Byte.TryParse(value, out b); Numeric.Value = b; } break; case Data_Types.INTEGER: Numeric.Name = UniqueName; Numeric.Top = top; Numeric.Left = left; Numeric.Tag = tag; Numeric.Width = 75; Numeric.Maximum = Int64.MaxValue; Numeric.Minimum = Int64.MinValue; p.Controls.Add(Numeric); left += Numeric.Width + 5; if (!String.IsNullOrEmpty(value)) { Int32 i = 0; Int32.TryParse(value, out i); Numeric.Value = i; } break; case Data_Types.SHORT: Numeric.Name = UniqueName; Numeric.Top = top; Numeric.Left = left; Numeric.Tag = tag; Numeric.Width = 75; Numeric.Maximum = short.MaxValue; Numeric.Minimum = short.MinValue; p.Controls.Add(Numeric); left += Numeric.Width + 5; if (!String.IsNullOrEmpty(value)) { short i = 0; short.TryParse(value, out i); Numeric.Value = i; } break; case Data_Types.STRING: TextBox tbx = new TextBox(); tbx.Name = UniqueName; tbx.Top = top; tbx.Left = left; tbx.Tag = tag; p.Controls.Add(tbx); tbx.Width = 400; left += tbx.Width + 5; if (!String.IsNullOrEmpty(value)) tbx.Text = value; break; case Data_Types.LIST: ComboBox cmbo = new ComboBox(); foreach(string option in options) cmbo.Items.Add(option); cmbo.Name = UniqueName; cmbo.DropDownStyle = ComboBoxStyle.DropDownList; cmbo.Top = top; cmbo.Left = left; cmbo.Tag = tag; p.Controls.Add(cmbo); left += cmbo.Width + 5; if (!String.IsNullOrEmpty(value)) cmbo.SelectedIndex = cmbo.Items.IndexOf(value); break; case Data_Types.COMPORT: Numeric.Name = UniqueName; Numeric.Top = top; Numeric.Left = left; Numeric.Tag = tag; Numeric.Width = 75; Numeric.Maximum = 99; Numeric.Minimum = 0; p.Controls.Add(Numeric); left += Numeric.Width + 5; if (!String.IsNullOrEmpty(value)) { Int32 i = 0; Int32.TryParse(value, out i); Numeric.Value = i; } break; } return left; }