Example #1
0
        protected void Init()
        {
            SuspendLayout();
            this.DoubleBuffered = true;

            this.clientWidth  = ClientRectangle.Width;
            this.clientHeight = ClientRectangle.Height;

            this.selectedColor = Color.Red;
            this.drawStyle     = DrawStyles.HSBHue;

            bmp = new Bitmap(clientWidth, clientHeight, PixelFormat.Format32bppArgb);

            mouseMoveTimer          = new Timer();
            mouseMoveTimer.Interval = 10;
            mouseMoveTimer.Tick    += new EventHandler(MouseMoveTimer_Tick);

            ClientSizeChanged += new EventHandler(ClientSizeChanged_Event);
            MouseDown         += new MouseEventHandler(MouseDown_Event);
            MouseEnter        += new EventHandler(MouseEnter_Event);
            MouseUp           += new MouseEventHandler(MouseUp_Event);
            Paint             += new PaintEventHandler(Paint_Event);

            ResumeLayout(false);
        }
Example #2
0
 public ColorPicker()
 {
     InitializeComponent();
     Size = new Size(290, 516);
     colorBox.ColorChanged    += ColorBox_ColorChanged;
     colorSlider.ColorChanged += ColorSlider_ColorChanged;
     selectedColor             = Color.FromArgb(255, 0, 0);
 }
Example #3
0
        protected void GetBoxColor()
        {
            switch (DrawStyle)
            {
            // HSB Color Space
            case DrawStyles.HSBHue:
                selectedColor.hsb.Saturation = (float)lastClicked.X / clientWidth;
                selectedColor.hsb.Brightness = (float)(1.0 - ((double)lastClicked.Y / clientHeight));
                selectedColor.UpdateHSB();
                break;

            case DrawStyles.HSBSaturation:
                selectedColor.hsb.Hue        = (float)lastClicked.X / clientWidth;
                selectedColor.hsb.Brightness = (float)(1.0 - ((double)lastClicked.Y / clientHeight));
                selectedColor.UpdateHSB();
                break;

            case DrawStyles.HSBBrightness:
                selectedColor.hsb.Hue        = (float)lastClicked.X / clientWidth;
                selectedColor.hsb.Saturation = (float)(1.0 - ((double)lastClicked.Y / clientHeight));
                selectedColor.UpdateHSB();
                break;

            // HSL Color Space
            case DrawStyles.HSLHue:
                selectedColor.hsl.Saturation = (float)lastClicked.X / clientWidth;
                selectedColor.hsl.Lightness  = (float)(1.0 - ((double)lastClicked.Y / clientHeight));
                selectedColor.UpdateHSL();
                break;

            case DrawStyles.HSLSaturation:
                selectedColor.hsl.Hue       = (float)lastClicked.X / clientWidth;
                selectedColor.hsl.Lightness = (float)(1.0 - ((double)lastClicked.Y / clientHeight));
                selectedColor.UpdateHSL();
                break;

            case DrawStyles.HSLLightness:
                selectedColor.hsl.Hue        = (float)lastClicked.X / clientWidth;
                selectedColor.hsl.Saturation = (float)(1.0 - ((double)lastClicked.Y / clientHeight));
                selectedColor.UpdateHSL();
                break;

            // RGB Color Space
            case DrawStyles.Red:
                selectedColor.argb.B = (int)Math.Round(255 * (double)lastClicked.X / (clientWidth));
                selectedColor.argb.G = (int)Math.Round(255 * (1.0 - ((double)lastClicked.Y / (clientHeight))));
                selectedColor.UpdateARGB();
                break;

            case DrawStyles.Green:
                selectedColor.argb.B = (int)Math.Round(255 * (double)lastClicked.X / (clientWidth));
                selectedColor.argb.R = (int)Math.Round(255 * (1.0 - ((double)lastClicked.Y / (clientHeight))));
                selectedColor.UpdateARGB();
                break;

            case DrawStyles.Blue:
                selectedColor.argb.R = (int)Math.Round(255 * (double)lastClicked.X / (clientWidth));
                selectedColor.argb.G = (int)Math.Round(255 * (1.0 - ((double)lastClicked.Y / (clientHeight))));
                selectedColor.UpdateARGB();
                break;

            case DrawStyles.xyz:
                // get the pixel from the bitmap to display to the user, but keep the selected color as the calculation so the cursor moves correctly
                absoluteColor = bmp.GetPixel(lastClicked.X.Clamp(0, clientWidth - 1), lastClicked.Y.Clamp(0, clientHeight - 1));
                absoluteColor.UpdateXYZ();

                // this isn't very accurate to the color under the cursor
                selectedColor.xyz.Y = (float)(100.0 * ((double)lastClicked.X / clientWidth));
                selectedColor.xyz.Z = (float)(150.0 * (1.0 - ((double)lastClicked.Y / clientHeight)));
                selectedColor.UpdateXYZ();
                break;
            }
        }
Example #4
0
 private void ColorBox_ColorChanged(object sender, ColorEventArgs e)
 {
     SelectedColor = e.Color;
     absoluteColor = e.AbsoluteColor;
 }
Example #5
0
 public ColorEventArgs(_Color color, _Color absoluteColor, DrawStyles drawStyle)
 {
     Color         = color;
     AbsoluteColor = absoluteColor;
     DrawStyle     = drawStyle;
 }
Example #6
0
 public ColorEventArgs(_Color color, _Color absoluteColor, ColorFormat format)
 {
     Color         = color;
     AbsoluteColor = absoluteColor;
     ColorType     = format;
 }