public void Draw(Graphics g, ColorHandler.RGB RGB) { // Given RGB values, calculate HSV and then update the screen. this.g = g; this.HSV = ColorHandler.RGBtoHSV(RGB); CalcCoordsAndUpdate(this.HSV); UpdateDisplay(); }
private void HandleRGBScroll(object sender, ScrollEventArgs e) { // If the R, G, or B values change, use this // code to update the HSV values and invalidate // the color wheel (so it updates the pointers). // Check the isInUpdate flag to avoid recursive events // when you update the NumericUpdownControls. changeType = ChangeStyle.RGB; RGB = new ColorHandler.RGB((int)nudRed.Value, (int)nudGreen.Value, (int)nudBlue.Value); SetHSV(ColorHandler.RGBtoHSV(RGB)); this.Invalidate(); }
private void HandleRGBScroll(object sender, EventArgs e) { // If the R, G, or B values change, use this // code to update the HSV values and invalidate // the color wheel (so it updates the pointers). // Check the isInUpdate flag to avoid recursive events // when you update the NumericUpdownControls. changeType = ChangeStyle.RGB; argb = new ColorHandler.ARGB(tbAlpha.Value, tbRed.Value, tbGreen.Value, tbBlue.Value); SetHSV(ColorHandler.RGBtoHSV(argb)); SetRGBLabels(argb); Invalidate(); }
private void UpdateColorInfo(ColorHandler.RGB RGB) { this.RGB = RGB; btnOK.BackColor = ColorHandler.RGBtoColor(RGB); btnOK.ForeColor = (RGB.Red < 180 && RGB.Green < 180) ? Color.White : Color.Black; //update color info switch (cbColorInfo.SelectedItem.ToString()) { case COLOR_INFO_RGB: RefreshNudValue(nudRed, RGB.Red); RefreshNudValue(nudBlue, RGB.Blue); RefreshNudValue(nudGreen, RGB.Green); break; case COLOR_INFO_HEX: string r = RGB.Red.ToString("X02"); string g = RGB.Green.ToString("X02"); string b = RGB.Blue.ToString("X02"); isInUpdate = true; tbFloatVals.Text = r + g + b; isInUpdate = false; break; case COLOR_INFO_FLOAT: string r2 = ((float)Math.Round(RGB.Red / 255f, 2)).ToString("F02", CultureInfo.InvariantCulture); string g2 = ((float)Math.Round(RGB.Green / 255f, 2)).ToString("F02", CultureInfo.InvariantCulture); string b2 = ((float)Math.Round(RGB.Blue / 255f, 2)).ToString("F02", CultureInfo.InvariantCulture); isInUpdate = true; tbFloatVals.Text = r2 + " " + g2 + " " + b2; isInUpdate = false; break; } //dispatch event further EventHandler <ColorChangedEventArgs> handler = OnColorChanged; if (handler != null) { handler(this, new ColorChangedEventArgs(RGB, ColorHandler.RGBtoHSV(RGB))); } }
private void ColorChooser1_Load(object sender, System.EventArgs e) { // Turn on double-buffering, so the form looks better. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); // These properties are set in design view, as well, but they // have to be set to false in order for the Paint // event to be able to display their contents. // Never hurts to make sure they're invisible. pnlSelectedColor.Visible = false; pnlBrightness.Visible = false; pnlColor.Visible = false; // Calculate the coordinates of the three // required regions on the form. Rectangle SelectedColorRectangle = new Rectangle(pnlSelectedColor.Location, pnlSelectedColor.Size); Rectangle BrightnessRectangle = new Rectangle(pnlBrightness.Location, pnlBrightness.Size); Rectangle ColorRectangle = new Rectangle(pnlColor.Location, pnlColor.Size); // Create the new ColorWheel class, indicating // the locations of the color wheel itself, the // brightness area, and the position of the selected color. myColorWheel = new ColorWheel( ColorRectangle, BrightnessRectangle, SelectedColorRectangle); myColorWheel.ColorChanged += new ColorWheel.ColorChangedEventHandler( this.myColorWheel_ColorChanged); // Set the RGB and HSV values // of the NumericUpDown controls. SetRGB(RGB); HSV = ColorHandler.RGBtoHSV(RGB); SetHSV(HSV); changeType = ChangeStyle.RGB; }
/// <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(); }