public void tbEdit_KeyPress(System.Object sender, System.Windows.Forms.KeyPressEventArgs e) { tParam param = default(tParam); if (curInputIndex >= 0) { param = paramList[curInputIndex]; if (e.KeyChar == Microsoft.VisualBasic.Strings.ChrW((System.Int32)Keys.Enter)) { tbEdit.Parent.Focus(); } else if (e.KeyChar == Microsoft.VisualBasic.Strings.ChrW((System.Int32)Keys.Escape)) { tbEdit.Text = param.value.ToString(); } else { if (param.input == cInputType.NUMBER) { // only numbers and backspace e.Handled = !RoutinesLibrary.Data.DataType.IntegerUtils.KeyIsNumber(e.KeyChar); } } } }
private void lblBut_Click(System.Object sender, System.EventArgs e) { int idx = TableLayoutPanel1.GetRow((Control)sender); tParam param = paramList[idx]; if (paramTableButtonClickedEvent != null) { paramTableButtonClickedEvent(param.paramName, param.value); } }
private void lblCheck_CheckedChanged(System.Object sender, System.Windows.Forms.MouseEventArgs e) { int idx = TableLayoutPanel1.GetRow((Control)sender); tParam param = paramList[idx]; if (paramTableCheckedChangedEvent != null) { paramTableCheckedChangedEvent(param.paramName, ((CheckBox)sender).Checked); } }
private void myEditRow(int iRow) { tParam param = paramList[iRow]; // if already editing, close previous edit if (curInputIndex >= 0) { myEditClose(); } curInputIndex = iRow; tbEdit.MaxLength = param.maxLengthValue; tbEdit.Size = param.lblValue.Size; tbEdit.Margin = param.lblValue.Margin; tbEdit.Text = ""; if (param.input == cInputType.NUMBER) { if (param.value == Configuration.noDataStr) { tbEdit.Text = ""; } else { tbEdit.Text = param.value; } } else { if (param.value == Configuration.noDataStr) { tbEdit.Text = ""; } else { tbEdit.Text = param.lblValue.Text; } } // send label to last row, first column param.lblValue.Visible = false; TableLayoutPanel1.SetCellPosition(param.lblValue, new TableLayoutPanelCellPosition(0, TableLayoutPanel1.RowCount - 1)); // position edit control (in second column) in current row TableLayoutPanel1.SetRow(tbEdit, curInputIndex); //tbEdit.Text = tbEdit.Location.X.ToString & ";" & tbEdit.Location.Y.ToString & " " & _ // param.lblValue.Location.X.ToString & ";" & param.lblValue.Location.Y.ToString tbEdit.Visible = true; tbEdit.Focus(); tbEdit.SelectionLength = tbEdit.TextLength; tbEdit.BringToFront(); }
private void myEditClose() { if (curInputIndex != -1) { tParam param = paramList[curInputIndex]; if (param.value != tbEdit.Text && !(param.value == Configuration.noDataStr && tbEdit.Text == "")) { setValue(param.paramName, tbEdit.Text); if (NewValueEvent != null) { NewValueEvent(param.paramName, param.value); } } // send edit control to the last row (same second column) tbEdit.Visible = false; TableLayoutPanel1.SetRow(tbEdit, TableLayoutPanel1.RowCount - 1); // re-position label to the editin row, second column TableLayoutPanel1.SetCellPosition(param.lblValue, new TableLayoutPanelCellPosition(1, curInputIndex)); param.lblValue.Visible = true; curInputIndex = -1; } }
private bool myValidateEdit(ref string sErr) { tParam param = default(tParam); int iValueMin = 0; int iValueMax = 0; string sValueMin = ""; string sValueMax = ""; string sAllowedValues = ""; bool bValueExists = false; string sValue = ""; sErr = ""; if (curInputIndex < 0) { return(true); } param = paramList[curInputIndex]; sValue = tbEdit.Text.Trim(); // check allowed values and limits, if any if (param.optionsValue != null) { // min value if (param.optionsValue.Length > 1) { try { sValueMin = param.optionsValue[1].Trim(); iValueMin = int.Parse(sValueMin); } catch (Exception) { iValueMin = 0; } } // max value if (param.optionsValue.Length > 2) { try { sValueMax = param.optionsValue[2].Trim(); iValueMax = int.Parse(sValueMax); } catch (Exception) { iValueMax = 0; } } // allowed values if (param.optionsValue.Length > 3) { sAllowedValues = param.optionsValue[3].Trim(); } // if allowed values (and no limits) if (!string.IsNullOrEmpty(sAllowedValues)) { if (("#" + sAllowedValues + "#").IndexOf("#" + sValue + "#") + 1 > 0) { bValueExists = true; } // value not allowed and no limits defined if (!bValueExists && string.IsNullOrEmpty(sValueMin) && string.IsNullOrEmpty(sValueMax)) { sErr = string.Format(Localization.getResStr(Configuration.paramsAllowedValuesId), sAllowedValues); return(false); } } // if limits try { if (!bValueExists && (!string.IsNullOrEmpty(sValueMin) || !string.IsNullOrEmpty(sValueMax))) { if (!string.IsNullOrEmpty(sValueMin) && !string.IsNullOrEmpty(sValueMax)) { if (int.Parse(sValue) < iValueMin || int.Parse(sValue) > iValueMax) { sErr = string.Format(Localization.getResStr(Configuration.paramsLimitsErrorId), iValueMin.ToString(), iValueMax.ToString()); return(false); } } else if (!string.IsNullOrEmpty(sValueMin)) { if (int.Parse(sValue) < iValueMin) { sErr = string.Format(Localization.getResStr(Configuration.paramsMinLimitErrorId), iValueMin.ToString()); return(false); } } else if (!string.IsNullOrEmpty(sValueMax)) { if (int.Parse(sValue) < iValueMin || int.Parse(tbEdit.Text) > iValueMax) { sErr = string.Format(Localization.getResStr(Configuration.paramsMaxLimitErrorId), iValueMax.ToString()); return(false); } } } } catch (Exception) { // } } return(true); }
public void ParamTable_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //Debug.Print("ParamTable_MouseUp") // if already editing, close previous edit //If curInputIndex >= 0 Then // Dim sErr As String = "" // If myValidateEdit(sErr) Then // myEditClose() // Else // MsgBox(sErr) // Return // End If //End If // If clicked over a row then editing its value if (mouseOverIndex != -1) // And sender.GetType Is GetType(Button) { // Depending on the input type tParam param = paramList[mouseOverIndex]; //Console.WriteLine(param.enabled) if (param.enabled) { if ((param.input == cInputType.TEXT | param.input == cInputType.NUMBER) && (e.Button == System.Windows.Forms.MouseButtons.Left)) { myEditRow(mouseOverIndex); } else if (param.input == cInputType.SWITCH) { // Moving to the next option int curOption = Array.IndexOf(param.optionsValue, param.value); // found value if (curOption >= 0) { if (e.Button == System.Windows.Forms.MouseButtons.Left && !bControlDown) // { curOption++; if (curOption > param.optionsValue.Length - 1) { curOption = 0; } setValue(param.paramName, param.optionsValue[curOption]); //param.lblValue.Text = param.optionsValue((curOption + 1) Mod param.optionsValue.Length) if (NewValueEvent != null) { NewValueEvent(param.paramName, param.optionsValue[curOption]); } } if (e.Button == System.Windows.Forms.MouseButtons.Left && bControlDown) { curOption--; if (curOption < 0) { curOption = param.optionsValue.Length - 1; } setValue(param.paramName, param.optionsValue[curOption]); //param.lblValue.Text = param.optionsValue(curOption) if (NewValueEvent != null) { NewValueEvent(param.paramName, param.optionsValue[curOption]); } } } else { setValue(param.paramName, param.optionsValue[0]); } } else if (param.input == cInputType.DROPLIST) { param.dropList.Visible = true; param.dropList.Show(param.lblValue, 0, param.lblValue.Height); } } else { curInputIndex = -1; } } else { curInputIndex = -1; } //Redrawing this.Invalidate(); }
// Adds a param to the table public void addParam(string paramName, string text, cInputType input, string[] options, string[] optionsText, bool bShowCheckBox = false, int maxLength = 0) { // Creating a new tParam tParam param = new tParam(); // Initializing it param.paramName = paramName; // param title param.lblText = new Label(); param.lblText.Name = "lblName" + paramName; param.lblText.ForeColor = textColor; //param.lblText.AutoSize = True param.lblText.Text = text; param.lblText.Margin = new Padding(3, 3, 3, 0); param.lblText.Padding = new Padding(0); param.lblText.TextAlign = ContentAlignment.TopLeft; // MiddleLeft param.lblText.BorderStyle = System.Windows.Forms.BorderStyle.None; // Windows.Forms.BorderStyle.FixedSingle param.lblText.MouseEnter += Param_MouseEnter; param.lblText.MouseLeave += Param_MouseLeave; //AddHandler param.lblText.MouseUp, AddressOf ParamTable_MouseUp // param data //param.lblValue = New Label //param.lblValue.BorderStyle = Windows.Forms.BorderStyle.None ' Windows.Forms.BorderStyle.FixedSingle param.lblValue = new Button(); param.lblValue.Name = "lblValue" + paramName; param.lblValue.FlatStyle = FlatStyle.Flat; param.lblValue.ForeColor = textColor; param.lblValue.Text = Configuration.noDataStr; param.lblValue.Margin = new Padding(0); param.lblValue.Padding = new Padding(0); param.lblValue.Height = 28; param.lblValue.TextAlign = ContentAlignment.TopRight; // MiddleRight param.dropList = new ContextMenuStrip(); param.maxLengthValue = maxLength; if (input == cInputType.BUTTON) { param.lblValue.FlatAppearance.BorderSize = 0; param.lblValue.FlatAppearance.BorderColor = Color.LightSteelBlue; param.lblValue.FlatAppearance.MouseDownBackColor = Color.LightSteelBlue; param.lblValue.FlatAppearance.MouseOverBackColor = Color.LightSteelBlue; param.lblValue.Cursor = Cursors.Hand; param.lblValue.Click += lblBut_Click; } else { param.lblValue.FlatAppearance.BorderSize = 0; param.lblValue.FlatAppearance.MouseDownBackColor = Color.Transparent; param.lblValue.FlatAppearance.MouseOverBackColor = Color.Transparent; //param.lblValue.AutoSize = True param.lblValue.MouseEnter += Param_MouseEnter; param.lblValue.MouseLeave += Param_MouseLeave; param.lblValue.MouseUp += ParamTable_MouseUp; param.lblValue.KeyDown += ParamTable_KeyDown; param.lblValue.KeyUp += ParamTable_KeyUp; if (input == cInputType.DROPLIST) { param.dropList.Items.Clear(); foreach (string optionEl in optionsText) { param.dropList.Items.Add(optionEl); } param.dropList.ItemClicked += dropList_ItemClicked; } } // param checkbox if (bShowCheckBox) { param.lblCheck = new CheckBox(); param.lblCheck.Name = "lblCheck" + paramName; param.lblCheck.Text = ""; param.lblCheck.MouseClick += lblCheck_CheckedChanged; } else { param.lblCheck = null; } // Setting the input param.input = input; param.value = Configuration.noDataStr; param.enabled = true; param.optionsValue = options; param.optionsText = optionsText; // Adding it to the list paramList.Add(param); // Adding the row TableLayoutPanel1.RowCount++; TableLayoutPanel1.SetRow(tbEdit, TableLayoutPanel1.RowCount - 1); // move edit control to the las row TableLayoutPanel1.Controls.Add(param.lblText, 0, TableLayoutPanel1.RowCount - 2); TableLayoutPanel1.Controls.Add(param.lblValue, 1, TableLayoutPanel1.RowCount - 2); if (param.lblCheck != null) { TableLayoutPanel1.Controls.Add(param.lblCheck, 2, TableLayoutPanel1.RowCount - 2); } TableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); param.lblText.Width = get_ptyColumnWidth(0); param.lblValue.Width = get_ptyColumnWidth(1); }