コード例 #1
0
ファイル: ColorSlider.cs プロジェクト: terman110/rgbCase
        /// <summary>
        /// Paints control adornments.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected virtual void PaintAdornments(PaintEventArgs e)
        {
            Point point;

            point = this.ValueToPoint(this.Value);

            // divider
            if (this.ShowValueDivider)
            {
                Point  start;
                Point  end;
                IntPtr hdc;

                if (this.Orientation == Orientation.Horizontal)
                {
                    start = new Point(point.X, this.BarBounds.Top);
                    end   = new Point(point.X, this.BarBounds.Bottom);
                }
                else
                {
                    start = new Point(this.BarBounds.Left, point.Y);
                    end   = new Point(this.BarBounds.Right, point.Y);
                }

                // draw a XOR'd line using Win32 API as this functionality isn't part of .NET
                hdc = e.Graphics.GetHdc();
                NativeMethods.SetROP2(hdc, NativeConstants.R2_NOT);
                NativeMethods.MoveToEx(hdc, start.X, start.Y, IntPtr.Zero);
                NativeMethods.LineTo(hdc, end.X, end.Y);
                e.Graphics.ReleaseHdc(hdc);
            }

            // drag nub
            if (this.NubStyle != ColorSliderNubStyle.None && this.SelectionGlyph != null)
            {
                int x;
                int y;

                if (this.Orientation == Orientation.Horizontal)
                {
                    x = point.X - this.NubSize.Width / 2;
                    if (this.NubStyle == ColorSliderNubStyle.BottomRight)
                    {
                        y = this.BarBounds.Bottom;
                    }
                    else
                    {
                        y = this.BarBounds.Top - this.NubSize.Height;
                    }
                }
                else
                {
                    y = point.Y - this.NubSize.Height / 2;
                    if (this.NubStyle == ColorSliderNubStyle.BottomRight)
                    {
                        x = this.BarBounds.Right;
                    }
                    else
                    {
                        x = this.BarBounds.Left - this.NubSize.Width;
                    }
                }

                e.Graphics.DrawImage(this.SelectionGlyph, x, y);
            }

            // focus
            if (this.Focused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, Rectangle.Inflate(this.BarBounds, -2, -2));
            }
        }