/// <summary> /// Sets the tuple coordinate names and the dimension of the tuple</summary> /// <param name="numericType">Numeric type of tuple coordinates</param> /// <param name="names">Array of tuple coordinate names; vector length (dimension) is array length</param> /// <remarks>All numeric types, except Decimal, are supported</remarks> public void Define(Type numericType, string[] names) { if (numericType != typeof(Int64) && numericType != typeof(UInt64) && numericType != typeof(Int32) && numericType != typeof(UInt32) && numericType != typeof(Int16) && numericType != typeof(UInt16) && numericType != typeof(SByte) && numericType != typeof(Byte) && numericType != typeof(Single) && numericType != typeof(Double)) { throw new ArgumentException("Unsupported numeric type"); } if (names == null || names.Length == 0) { throw new ArgumentException("Must have at least 1 coordinate in the tuple"); } DoubleBuffered = true; m_numericType = numericType; while (Controls.Count > 0) { Controls[0].Dispose(); } if (s_lblFormat == null) { s_lblFormat = new StringFormat(); s_lblFormat.Alignment = StringAlignment.Center; s_lblFormat.LineAlignment = StringAlignment.Near; s_lblFormat.Trimming = StringTrimming.Character; } m_labelWidth = new int[names.Length]; m_labelWidth[0] = -1; // to indicate uninitialized state. SuspendLayout(); // custom tab handling. TabStop = false; for (int i = 0; i < names.Length; i++) { var textBox = new NumericTextBox(m_numericType); textBox.BorderStyle = BorderStyle.None; textBox.TabStop = false; textBox.Name = names[i]; textBox.ScaleFactor = m_scaleFactor; textBox.ValueEdited += textBox_ValueEdited; Controls.Add(textBox); } ResumeLayout(); }
/// <summary> /// Sets the matrix element type and the dimensions of the matrix</summary> /// <param name="numericType">Numeric type of matrix elements</param> /// <param name="rows">Number of matrix rows</param> /// <param name="columns">Number of matrix columns</param> /// <remarks>All numeric types, except Decimal, are supported</remarks> public void Define(Type numericType, int rows, int columns) { if (numericType != typeof(Int64) && numericType != typeof(UInt64) && numericType != typeof(Int32) && numericType != typeof(UInt32) && numericType != typeof(Int16) && numericType != typeof(UInt16) && numericType != typeof(SByte) && numericType != typeof(Byte) && numericType != typeof(Single) && numericType != typeof(Double)) { throw new ArgumentException("Unsupported numeric type"); } if (rows < 1 || columns < 1) { throw new ArgumentException("Must have at least 1 row and column in the matrix"); } m_numericType = numericType; m_rows = rows; m_columns = columns; for (int i = 0; i < Controls.Count;) { Control control = Controls[0]; control.Parent = null; control.Dispose(); } SuspendLayout(); NumericTextBox textBox = null; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { textBox = new NumericTextBox(m_numericType); textBox.BorderStyle = BorderStyle.None; textBox.Name = "M" + i + j; textBox.TabStop = true; textBox.TabIndex = i; textBox.ScaleFactor = m_scaleFactor; textBox.ValueEdited += textBox_ValueEdited; Controls.Add(textBox); } } // TODO needs dpi adjustment Size = new Size(80 * columns, textBox.Height * rows - 1); ResumeLayout(); }
/// <summary> /// Constructor with initial and bounding values</summary> /// <param name="value">Initial value</param> /// <param name="min">Minimum value</param> /// <param name="max">Maximum value</param> public FloatInputControl(float value, float min, float max) { if (min >= max) { throw new ArgumentException("min must be less than max"); } DoubleBuffered = true; m_min = min; m_max = max; m_value = MathUtil.Clamp(value, m_min, m_max); m_lastChange = m_value; m_lastEdit = m_value; m_textBox = new NumericTextBox(); m_textBox.BorderStyle = BorderStyle.None; m_textBox.Name = "m_textBox"; m_spinner = new CompactSpinner(); m_spinner.GotFocus += (sender, e) => m_textBox.Focus(); SuspendLayout(); UpdateTextBox(); Controls.Add(m_textBox); Controls.Add(m_spinner); ResumeLayout(false); PerformLayout(); m_textBox.ValueEdited += (sender, e) => { float val = (float)m_textBox.Value; SetValue(val, false); EndEdit(true); }; m_spinner.Changed += (sender, e) => { // might be better to expose delta as property float delta = (m_max - m_min) / 100.0f; float newValue = Value + (float)e.Value * delta; SetValue(newValue, false); }; m_textBox.SizeChanged += (sender, e) => Height = m_textBox.Height + 3; SizeChanged += (sender, e) => { m_spinner.Bounds = new Rectangle(0, 0, Height, Height); m_textBox.Bounds = new Rectangle(m_spinner.Width, 0, Width - m_spinner.Width, m_textBox.Height); }; }
/// <summary> /// Sets the matrix element type and the dimensions of the matrix</summary> /// <param name="numericType">Numeric type of matrix elements</param> /// <param name="rows">Number of matrix rows</param> /// <param name="columns">Number of matrix columns</param> /// <remarks>All numeric types, except Decimal, are supported</remarks> public void Define(Type numericType, int rows, int columns) { if (numericType != typeof(Int64) && numericType != typeof(UInt64) && numericType != typeof(Int32) && numericType != typeof(UInt32) && numericType != typeof(Int16) && numericType != typeof(UInt16) && numericType != typeof(SByte) && numericType != typeof(Byte) && numericType != typeof(Single) && numericType != typeof(Double)) { throw new ArgumentException("Unsupported numeric type"); } if (rows < 1 || columns < 1) { throw new ArgumentException("Must have at least 1 row and column in the matrix"); } m_numericType = numericType; m_rows = rows; m_columns = columns; while (Controls.Count > 0) { Controls[0].Dispose(); } SuspendLayout(); // custom tab handling. TabStop = false; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { var textBox = new NumericTextBox(m_numericType); textBox.TabStop = false; textBox.BorderStyle = BorderStyle.FixedSingle; textBox.Name = "M" + i + j; textBox.ScaleFactor = m_scaleFactor; textBox.ValueEdited += textBox_ValueEdited; Controls.Add(textBox); } } ResumeLayout(); }
/// <summary> /// Constructor with initial and bounding values</summary> /// <param name="value">Initial value</param> /// <param name="min">Minimum value</param> /// <param name="max">Maximum value</param> public IntInputControl(int value, int min, int max) { if (min >= max) { throw new ArgumentException("min must be less than max"); } DoubleBuffered = true; m_min = min; m_max = max; m_value = MathUtil.Clamp(value, m_min, m_max); m_lastChange = m_value; m_lastEdit = m_value; m_textBox = new NumericTextBox(typeof(int)); m_textBox.BorderStyle = BorderStyle.None; m_textBox.Name = "m_textBox"; m_spinner = new CompactSpinner(); m_spinner.GotFocus += (sender, e) => m_textBox.Focus(); SuspendLayout(); UpdateTextBox(); Controls.Add(m_textBox); Controls.Add(m_spinner); ResumeLayout(false); PerformLayout(); m_textBox.ValueEdited += (sender, e) => { int val = (int)m_textBox.Value; SetValue(val, false); EndEdit(true); }; m_spinner.Changed += (sender, e) => { int newValue = Value + e.Value; SetValue(newValue, false); }; m_textBox.SizeChanged += (sender, e) => this.Height = m_textBox.Height + 3; SizeChanged += (sender, e) => { m_spinner.Bounds = new Rectangle(0, 0, Height, Height); m_textBox.Bounds = new Rectangle(m_spinner.Width, 0, Width - m_spinner.Width, m_textBox.Height); }; }
private void textBox_ValueEdited(object sender, EventArgs e) { NumericTextBox textbox = (NumericTextBox)sender; m_component = Controls.IndexOf(textbox); Array value = Value as Array; m_editing = true; OnValueChanged(EventArgs.Empty); m_lastChange = value; if (!ContainsFocus && m_editing) { OnValueEdited(EventArgs.Empty); m_lastEdit = value; m_editing = false; } }
/// <summary> /// Processes a dialog key</summary> /// <param name="keyData">One of the System.Windows.Forms.Keys values that represents the key to process</param> /// <returns>True iff the key was processed by the control</returns> protected override bool ProcessDialogKey(Keys keyData) { if (keyData == Keys.Tab) { bool focusOnNext = false; foreach (NumericTextBox textBox in Controls) { if (focusOnNext) { textBox.Focus(); return(true); } if (textBox.Focused) { focusOnNext = true; } } } else if (keyData == (Keys.Tab | Keys.Shift)) { NumericTextBox previous = null; foreach (NumericTextBox textBox in Controls) { if (textBox.Focused) { if (previous != null) { previous.Focus(); return(true); } break; } previous = textBox; } } return(base.ProcessDialogKey(keyData)); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"></see> event</summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int y = Margin.Top; NumericTextBox textBox = Controls[0] as NumericTextBox;; for (int i = 0; i < m_rows - 1; i++) { y += textBox.Height; e.Graphics.DrawLine(SystemPens.Control, 0, y, Width, y); ++y; } int x = Margin.Left; for (int j = 0; j < m_columns; ++j) { x += (m_coordinateWidth); e.Graphics.DrawLine(SystemPens.Control, x, 0, x, Height); x += 1; } }
/// <summary> /// Processes a dialog key</summary> /// <param name="keyData">One of the System.Windows.Forms.Keys values that represents the key to process</param> /// <returns>True iff the key was processed by the control</returns> protected override bool ProcessDialogKey(Keys keyData) { NumericTextBox focusTextBox = null; foreach (NumericTextBox ctrl in Controls) { if (ctrl.Focused) { focusTextBox = ctrl; break; } } int index = focusTextBox == null ? -1 : Controls.IndexOf(focusTextBox); if (keyData == Keys.Tab || keyData == Keys.Enter) { // if on last NumericTextBox then don't process tab NumericTextBox last = (NumericTextBox)Controls[Controls.Count - 1]; if (focusTextBox != last) { Controls[index + 1].Focus(); return(true); } } else if (keyData == (Keys.Tab | Keys.Shift)) { NumericTextBox first = (NumericTextBox)Controls[0]; if (focusTextBox != first && index != -1) { Controls[index - 1].Focus(); return(true); } } return(base.ProcessDialogKey(keyData)); }