static HslColor() { Empty = new HslColor { IsEmpty = true }; }
private void TxtColor_TextChanged(object sender, EventArgs e) { if (!LockUpdates) { LockUpdates = true; // Process text color var regex = _ckbHex.CheckState == CheckState.Checked ? new Regex(@"#[A-F0-9]{2}[A-F0-9]{2}[A-F0-9]{2}") : new Regex(@"\d{1,3}, \d{1,3}, \d{1,3}"); if (regex.IsMatch(_txtColor.Text)) { int r, g, b; if (_txtColor.Text.StartsWith("#")) { r = Convert.ToInt32(_txtColor.Text.Substring(1, 2), 16); g = Convert.ToInt32(_txtColor.Text.Substring(3, 2), 16); b = Convert.ToInt32(_txtColor.Text.Substring(5, 2), 16); } else { var parts = _txtColor.Text.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); r = int.Parse(parts[0]); g = int.Parse(parts[1]); b = int.Parse(parts[2]); } Color = Color.FromArgb(r, g, b); HslColor = new HslColor(_color); } LockUpdates = false; } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.BackColorChanged" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnBackColorChanged(EventArgs e) { base.OnBackColorChanged(e); _borderColor = new HslColor(BackColor); _borderColor.L -= 0.1F; }
/// <summary> /// Gets the point within the wheel representing the source color. /// </summary> /// <param name="color">The color.</param> protected virtual PointF GetColorLocation(HslColor color) { double angle; double radius; angle = color.H * Math.PI / 180; ; radius = _radius * color.S; return this.GetColorLocation(angle, radius); }
/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { // Set serveral option for paint SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); _borderColor = new HslColor(BackColor); _borderColor.L -= 0.1F; RecreatePath(); }