/// <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> /// 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); }; }
/// <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.BackColor = m_textBox.BackColor; 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> /// 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.BackColor = m_textBox.BackColor; 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); }; }