示例#1
0
        /// <summary>
        /// Draws the slider itself in client coordinates
        /// </summary>
        /// <param name="g"></param>
        /// <param name="clipRectangle"></param>
        protected virtual void OnDrawSlider(Graphics g, Rectangle clipRectangle)
        {
            Color light = _sliderColor.Lighter(.3F);
            Color dark = _sliderColor.Darker(.3F);
            Point tl = new Point();
            Point br = new Point();
            double val = (Value - Minimum) / (Maximum - Minimum);
            int x, y, w, h;

            if (_orientation == Orientation.Horizontal)
            {
                w = 10;
                int span = Width - w - 1;
                float vSpan = _rampRectangle.Height - _rampRadius * 2;
                y = _rampRectangle.Top;
                if (_flipRamp)
                {
                    x = (int)(span * (1 - val));
                    // h = (int)(_rampRadius * 2 + vSpan * (1 - val));
                }
                else
                {
                    x = (int)(val * span);
                }
                h = (int)(_rampRadius * 2 + vSpan * val);
                if (h < 10) h = 10;
                if (_invertRamp == false)
                {
                    y = _rampRectangle.Bottom - h;
                }
            }
            else
            {
                h = 10;
                int span = Height - h - 1;
                x = _rampRectangle.Left;
                float hSpan = _rampRectangle.Width - _rampRadius * 2;
                if (_flipRamp)
                {
                    y = (int)(span * val);
                    //w = (int)(_rampRadius * 2 + hSpan * (1 - val));
                }
                else
                {
                    y = (int)(span * (1 - val));
                }
                w = (int)(_rampRadius * 2 + hSpan * val);
                if (w < 10) w = 10;
                if (_invertRamp == false)
                {
                    x = _rampRectangle.Right - w;
                }
            }
            if (x > _rampRectangle.Width) x = _rampRectangle.Width;
            if (x < 0) x = 0;
            if (y > _rampRectangle.Height) y = _rampRectangle.Height;
            if (y < 0) y = 0;
            tl.X = x;
            tl.Y = y;
            br.X = x + w;
            br.Y = y + h;
            try
            {
                LinearGradientBrush lgb = new LinearGradientBrush(tl, br, light, dark);
                Rectangle bounds = new Rectangle(x, y, w, h);
                _sliderRectangle = bounds;
                GraphicsPath gp = new GraphicsPath();
                gp.AddRoundedRectangle(bounds, (int)Math.Round(_sliderRadius));
                g.FillPath(lgb, gp);
                g.DrawPath(Pens.Gray, gp);
                gp.Dispose();
                GraphicsPath bottomRight = new GraphicsPath();
                bottomRight.AddRoundedRectangleBottomRight(bounds, (int)Math.Round(_sliderRadius));
                g.DrawPath(Pens.DarkGray, bottomRight);
                bottomRight.Dispose();
                lgb.Dispose();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }