Пример #1
0
        private static Color[] SimilarColors(int red, int green, int blue)
        {
            var color0 = new RgbColor(red, green, blue).ToHsl();

            var delta  = Faker.Random.Int(25, 30) / 360.0;
            var color1 = new HslColor((color0.H + delta) % 1.0, color0.S, color0.L);
            var color2 = new HslColor((color0.H - delta) % 1.0, color0.S, color0.L);

            return(new[] { color0.ToColor(), color1.ToColor(), color2.ToColor() });
        }
Пример #2
0
        private void setColor(RgbColor color)
        {
            Color c = color.ToColor();

            colorControl.SelectedColor = c;

            if (NeedUpdateUI != null)
            {
                NeedUpdateUI(this, EventArgs.Empty);
            }
        }
Пример #3
0
        private void UpDown_ValueChanged(object sender, System.EventArgs e)
        {
            if (IgnoreChangedEvents)
            {
                return;
            }
            else
            {
                PushIgnoreChangedEvents();
                if (sender == redUpDown || sender == greenUpDown || sender == blueUpDown)
                {
                    string hexText = GetHexNumericUpDownValue((int)redUpDown.Value, (int)greenUpDown.Value, (int)blueUpDown.Value);
                    hexBox.Text = hexText;

                    Color rgbColor = Color.FromArgb((byte)redUpDown.Value, (byte)greenUpDown.Value, (byte)blueUpDown.Value);

                    SetColorGradientMinMaxColorsRgb(rgbColor.R, rgbColor.G, rgbColor.B);
                    SetColorGradientValuesRgb(rgbColor.R, rgbColor.G, rgbColor.B);

                    SyncHsvFromRgb(rgbColor);

                    Color = rgbColor;
                }
                else if (sender == hexBox)
                {
                    int hexInt = 0;

                    if (hexBox.Text.Length > 0)
                    {
                        try
                        {
                            hexInt = int.Parse(hexBox.Text, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture);
                        }

                        // Needs to be changed so it reads what the RGB values were last
                        catch (FormatException)
                        {
                            hexInt      = 0;
                            hexBox.Text = "";
                        }
                        catch (OverflowException)
                        {
                            hexInt      = 16777215;
                            hexBox.Text = "FFFFFF";
                        }

                        if (!((hexInt <= 16777215) && (hexInt >= 0)))
                        {
                            hexInt      = 16777215;
                            hexBox.Text = "FFFFFF";
                        }
                    }

                    int newRed   = ((hexInt & 0xff0000) >> 16);
                    int newGreen = ((hexInt & 0x00ff00) >> 8);
                    int newBlue  = (hexInt & 0x0000ff);

                    Utility.SetNumericUpDownValue(redUpDown, newRed);
                    Utility.SetNumericUpDownValue(greenUpDown, newGreen);
                    Utility.SetNumericUpDownValue(blueUpDown, newBlue);

                    SetColorGradientMinMaxColorsRgb(newRed, newGreen, newBlue);
                    SetColorGradientValuesRgb(newRed, newGreen, newBlue);

                    Color rgbColor = Color.FromArgb((byte)newRed, (byte)newGreen, (byte)newBlue);
                    SyncHsvFromRgb(rgbColor);
                    Color = rgbColor;
                }
                else if (sender == hueUpDown || sender == saturationUpDown || sender == valueUpDown)
                {
                    HsvColor oldHsvColor = colorWheel.HsvColor;
                    HsvColor newHsvColor = new HsvColor((int)hueUpDown.Value, (int)saturationUpDown.Value, (int)valueUpDown.Value);

                    if (oldHsvColor != newHsvColor)
                    {
                        colorWheel.HsvColor = newHsvColor;

                        SetColorGradientValuesHsv(newHsvColor.Hue, newHsvColor.Saturation, newHsvColor.Value);
                        SetColorGradientMinMaxColorsHsv(newHsvColor.Hue, newHsvColor.Saturation, newHsvColor.Value);

                        SyncRgbFromHsv(newHsvColor);
                        RgbColor rgbColor = newHsvColor.ToRgb();
                        Color = rgbColor.ToColor();
                    }
                }
                PopIgnoreChangedEvents();
            }
        }
    private void setColor(RgbColor color)
    {
      Color c = color.ToColor();
      colorControl.SelectedColor = c;

      if (NeedUpdateUI != null)
      {
        NeedUpdateUI(this, EventArgs.Empty);
      }
    }