コード例 #1
0
        /// <summary>
        /// Controls the actual drawing for this gradient slider control.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="clipRectangle"></param>
        protected virtual void OnDraw(Graphics g, Rectangle clipRectangle)
        {
            GraphicsPath gp        = new GraphicsPath();
            Rectangle    innerRect = new Rectangle(_leftHandle.Width, 3, Width - 1 - _rightHandle.Width - _leftHandle.Width,
                                                   Height - 1 - 6);

            gp.AddRoundedRectangle(innerRect, 2);

            if (Width == 0 || Height == 0)
            {
                return;
            }
            // Create a rounded gradient effect as the backdrop that other colors will be drawn to
            LinearGradientBrush silver = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical);

            g.FillPath(silver, gp);
            silver.Dispose();

            LinearGradientBrush lgb = new LinearGradientBrush(innerRect, MinimumColor, MaximumColor, LinearGradientMode.Horizontal);

            g.FillPath(lgb, gp);
            lgb.Dispose();

            g.DrawPath(Pens.Gray, gp);
            gp.Dispose();

            if (Enabled)
            {
                _leftHandle.Draw(g);
                _rightHandle.Draw(g);
            }
        }
コード例 #2
0
        private void DrawColorSemicircle(Graphics g)
        {
            Rectangle bounds = GetSemicircleBounds();

            if (bounds.Width <= 0 || bounds.Height <= 0)
            {
                return;
            }

            GraphicsPath gp = new GraphicsPath();

            gp.AddPie(new Rectangle(-bounds.Width, bounds.Y, bounds.Width * 2, bounds.Height), -90, 180);
            Rectangle           roundBounds = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
            LinearGradientBrush lgb         = new LinearGradientBrush(roundBounds, BackColor.Lighter(.5F), BackColor.Darker(.5F), LinearGradientMode.ForwardDiagonal);

            g.FillPath(lgb, gp);
            lgb.Dispose();
            gp.Dispose();

            gp = new GraphicsPath();

            Rectangle innerRound = GetInnerSemicircleBounds();

            if (innerRound.Width <= 0 || innerRound.Height <= 0)
            {
                return;
            }

            gp.AddPie(new Rectangle(innerRound.X - innerRound.Width, innerRound.Y, innerRound.Width * 2, innerRound.Height), -90, 180);
            PointF     center = new PointF(innerRound.X + (innerRound.Width / 2), innerRound.Y + (innerRound.Height / 2));
            float      x      = center.X - innerRound.Width;
            float      y      = center.Y - innerRound.Height;
            float      w      = innerRound.Width * 2;
            float      h      = innerRound.Height * 2;
            RectangleF circum = new RectangleF(x, y, w, h);

            GraphicsPath coloring = new GraphicsPath();

            coloring.AddEllipse(circum);
            PathGradientBrush pgb = new PathGradientBrush(coloring)
            {
                CenterColor    = _color.Lighter(.2F),
                SurroundColors = new[] { _color.Darker(.2F) },
                CenterPoint    = new PointF(innerRound.X + 3, innerRound.Y + (innerRound.Height / 3))
            };

            g.FillPath(pgb, gp);
            lgb.Dispose();
            gp.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// Instructs this button to draw itself.
        /// </summary>
        /// <param name="g">The graphics surface to draw to.</param>
        public void Draw(Graphics g)
        {
            if (Bounds.Width == 0 || Bounds.Height == 0)
            {
                return;
            }

            Pen   border = null;
            Brush fill   = null;

            if (!Selected && !Highlighted)
            {
                border = new Pen(Color.Gray);
                fill   = new LinearGradientBrush(Bounds, BackColor.Lighter(.2f), BackColor.Darker(.2f), 45);
            }

            if (!Selected && Highlighted)
            {
                border = new Pen(Color.FromArgb(216, 240, 250));
                fill   = new LinearGradientBrush(Bounds, Color.FromArgb(245, 250, 253), Color.FromArgb(232, 245, 253), LinearGradientMode.Vertical);
            }

            if (Selected && !Highlighted)
            {
                border = new Pen(Color.FromArgb(153, 222, 253));
                fill   = new LinearGradientBrush(Bounds, Color.FromArgb(241, 248, 253), Color.FromArgb(213, 239, 252), LinearGradientMode.Vertical);
            }

            if (Selected && Highlighted)
            {
                border = new Pen(Color.FromArgb(182, 230, 251));
                fill   = new LinearGradientBrush(Bounds, Color.FromArgb(232, 246, 253), Color.FromArgb(196, 232, 250), LinearGradientMode.Vertical);
            }

            using (GraphicsPath gp = new GraphicsPath())
            {
                gp.AddRoundedRectangle(Bounds, 2);
                if (fill != null)
                {
                    g.FillPath(fill, gp);
                }
                if (border != null)
                {
                    g.DrawPath(border, gp);
                }
            }

            fill?.Dispose();
        }
コード例 #4
0
        /// <summary>
        /// Controls the actual drawing for this gradient slider control.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="clipRectangle"></param>
        protected virtual void OnDraw(Graphics g, Rectangle clipRectangle)
        {
            GraphicsPath gp        = new GraphicsPath();
            Rectangle    innerRect = new Rectangle(_leftHandle.Width, 3, Width - 1 - _rightHandle.Width - _leftHandle.Width,
                                                   Height - 1 - 6);

            gp.AddRoundedRectangle(innerRect, 2);

            if (Width == 0 || Height == 0)
            {
                return;
            }
            // Create a rounded gradient effect as the backdrop that other colors will be drawn to
            LinearGradientBrush silver = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical);

            g.FillPath(silver, gp);
            silver.Dispose();

            LinearGradientBrush lgb = new LinearGradientBrush(innerRect, Color.White, Color.White, LinearGradientMode.Horizontal);

            Color[] colors    = new Color[37];
            float[] positions = new float[37];

            for (int i = 0; i <= 36; i++)
            {
                int j = _inverted ? 36 - i : i;
                colors[j]    = SymbologyGlobal.ColorFromHsl((i * 10 + _hueShift) % 360, 1, .7).ToTransparent(.7f);
                positions[i] = i / 36f;
            }

            ColorBlend cb = new ColorBlend();

            cb.Colors               = colors;
            cb.Positions            = positions;
            lgb.InterpolationColors = cb;
            g.FillPath(lgb, gp);
            lgb.Dispose();

            g.DrawPath(Pens.Gray, gp);
            gp.Dispose();

            if (Enabled)
            {
                _leftHandle.Draw(g);
                _rightHandle.Draw(g);
            }
        }
コード例 #5
0
        /// <summary>
        /// Controls the actual drawing for this gradient slider control.
        /// </summary>
        /// <param name="g">The graphics object used for drawing.</param>
        /// <param name="clipRectangle">The clip rectangle.</param>
        protected virtual void OnDraw(Graphics g, Rectangle clipRectangle)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            LinearGradientBrush lgb = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.2F), LinearGradientMode.Vertical);

            g.FillRectangle(lgb, ClientRectangle);
            lgb.Dispose();

            int l = Convert.ToInt32((Width * (LeftHandle.Position - _min)) / (_max - _min));
            int r = Convert.ToInt32((Width * (RightHandle.Position - _min)) / (_max - _min));

            Rectangle a = new Rectangle(0, 5, l, Height - 10);
            Rectangle b = new Rectangle(l, 5, r - l, Height - 10);
            Rectangle c = new Rectangle(r, 5, Right - r, Height - 10);

            if (a.Width > 0)
            {
                SolidBrush sb = new SolidBrush(_minColor);
                g.FillRectangle(sb, a);
                sb.Dispose();
            }

            if (b.Width > 0)
            {
                LinearGradientBrush center = new LinearGradientBrush(new Point(b.X, 0), new Point(b.Right, 0), _minColor, _maxColor);
                g.FillRectangle(center, b);
                center.Dispose();
            }

            if (c.Width > 0)
            {
                SolidBrush sb = new SolidBrush(_maxColor);
                g.FillRectangle(sb, c);
                sb.Dispose();
            }

            if (Enabled)
            {
                LeftHandle.Draw(g);
                RightHandle.Draw(g);
            }
        }