public static RGBtoHSV ( RGB RGB ) : HSV | ||
RGB | RGB | The R(ed)G(reen)B(lue) values |
return | HSV |
/// <summary> /// The timer is used to control the color wheel update from the text boxes. /// If we update instantly, we are unable to type, therefore allow a delay for typing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { // The tag contains the control that started the timer Control c = (Control)timer1.Tag; try { if ((Color)c.Tag == Color.White) { this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Red) { this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Green) { this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Blue) { this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } this.hsvColor = ColorHandler.RGBtoHSV(this.color); updateBar(); } catch { } timer1.Stop(); }
/// <summary> /// The control_ lost focus. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Control_LostFocus(object sender, EventArgs e) { // In case they leave the text box before the timer has expired, call the // timer1_tick to update the color wheel with the new data. if (timer1.Enabled) { timer1_Tick(sender, e); } hsvColor = ColorHandler.RGBtoHSV(this.color); updateBar(); this.Refresh(); }
/// <summary> /// The control_ text changed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Control_TextChanged(object sender, EventArgs e) { if (updatingColors) { return; } Control c = (Control)sender; try { if ((Color)c.Tag == Color.White) { this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Red) { this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Green) { this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Blue) { this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } this.hsvColor = ColorHandler.RGBtoHSV(this.color); updateBar(); } catch { } }
/// <summary> /// The control_ lost focus. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Control_LostFocus(object sender, EventArgs e) { hsvColor = ColorHandler.RGBtoHSV(this.color); updateBar(); this.Refresh(); }