void OnEditTextChanged(object sender, EventArgs e) { if (_preventReentrantCalls == false) { TextBox tb = sender as TextBox; int value = (tb.Text.Length > 0 ? Int32.Parse(tb.Text) : 0); if (value > 255) { value = 255; } if (sender == _rEdit) { _color = Color.FromArgb(_color.A, value, _color.G, _color.B); } else if (sender == _gEdit) { _color = Color.FromArgb(_color.A, _color.R, value, _color.B); } else if (sender == _bEdit) { _color = Color.FromArgb(_color.A, _color.R, _color.G, value); } else if (sender == _aEdit) { _color = Color.FromArgb(value, _color.R, _color.G, _color.B); } _alphaBar.Value = _color.A; _sbMapPicker.ResetColor(); _sbMapPicker.Color = _color; double h, s, b; ColorUtils.RgbToHsb(_color, out h, out s, out b); _preventReentrantCalls = true; _hueBar.Value = (int)Math.Round(h / 360.0 * 255.0); _preventReentrantCalls = false; } }
public void InitializeContent(PropertyEnumerator propEnum, string currentValue, object valueKey) { _color = (Color)propEnum.Property.Value.GetValue(); Width = 200; Height = 212; BackColor = SystemColors.Control; double h, s, b; ColorUtils.RgbToHsb(_color, out h, out s, out b); _hueBar.Bounds = new Rectangle(35, 10, 155, 12); _hueBar.Margins = new Win32Calls.RECT(25, 1, 1, 1); _hueBar.Label = "Hue"; _hueBar.Value = (int)Math.Round(h / 360.0 * 255.0); _hueBar.ValueChanged += new EventHandler(OnTrackBarValueChanged); _hueBar.TabIndex = 2; _sbMapPicker.Color = _color; _sbMapPicker.Bounds = new Rectangle(40, 30, 150, 150); _sbMapPicker.ValueChanged += new EventHandler(OnSbMapValueChanged); _sbMapPicker.TabIndex = 3; _alphaBar.Bounds = new Rectangle(10, 10, 20, 100); _alphaBar.Margins = new Win32Calls.RECT(1, 1, 1, 1); _alphaBar.Orientation = Orientation.Vertical; _alphaBar.ReversedOrigin = true; _alphaBar.Value = _color.A; _alphaBar.ValueChanged += new EventHandler(OnTrackBarValueChanged); _alphaBar.TabIndex = 1; _rLabel.TextAlign = ContentAlignment.MiddleLeft; _rLabel.Bounds = new Rectangle(10, 185, 15, 19); _rLabel.Text = "R"; _rEdit.AutoSize = false; _rEdit.Bounds = new Rectangle(25, 185, 26, 19); _rEdit.Text = _color.R.ToString(); _rEdit.MaxLength = 3; _rEdit.KeyPress += new KeyPressEventHandler(OnEditKeyPress); _rEdit.TextChanged += new EventHandler(OnEditTextChanged); _gLabel.TextAlign = ContentAlignment.MiddleLeft; _gLabel.Bounds = new Rectangle(56, 185, 15, 19); _gLabel.Text = "G"; _gEdit.AutoSize = false; _gEdit.Bounds = new Rectangle(71, 185, 26, 19); _gEdit.Text = _color.G.ToString(); _gEdit.MaxLength = 3; _gEdit.KeyPress += new KeyPressEventHandler(OnEditKeyPress); _gEdit.TextChanged += new EventHandler(OnEditTextChanged); _bLabel.TextAlign = ContentAlignment.MiddleLeft; _bLabel.Bounds = new Rectangle(102, 185, 15, 19); _bLabel.Text = "B"; _bEdit.AutoSize = false; _bEdit.Bounds = new Rectangle(117, 185, 26, 19); _bEdit.Text = _color.B.ToString(); _bEdit.MaxLength = 3; _bEdit.KeyPress += new KeyPressEventHandler(OnEditKeyPress); _bEdit.TextChanged += new EventHandler(OnEditTextChanged); _aLabel.TextAlign = ContentAlignment.MiddleLeft; _aLabel.Bounds = new Rectangle(148, 185, 15, 19); _aLabel.Text = "A"; _aEdit.AutoSize = false; _aEdit.Bounds = new Rectangle(163, 185, 26, 19); _aEdit.Text = _color.A.ToString(); _aEdit.MaxLength = 3; _aEdit.KeyPress += new KeyPressEventHandler(OnEditKeyPress); _aEdit.TextChanged += new EventHandler(OnEditTextChanged); Controls.Add(_hueBar); Controls.Add(_sbMapPicker); Controls.Add(_alphaBar); Controls.Add(_rEdit); Controls.Add(_gEdit); Controls.Add(_bEdit); Controls.Add(_aEdit); Controls.Add(_rLabel); Controls.Add(_gLabel); Controls.Add(_bLabel); Controls.Add(_aLabel); }