Esempio n. 1
0
        //paint slider
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Rectangle bandrct = this.GetBandRectangle();

            if (bandrct.Width < 1 || bandrct.Height < 1)
            {
                return;
            }
            //forecolor adjust
            Color forecolor =
                this._fadetype == FadeType.Internal?
                ColorUtility.AoverB(this.GetSelectedColor(), Color.Silver):               //blended with checker
                this.BackColor;

            if (_highlighted)
            {
                forecolor = ColorUtility.MaxContrastRBTo(forecolor);              //color
            }
            else
            {
                forecolor = ColorUtility.MaxContrastTo(forecolor);              //blackwhite
            }
            int position;

            //start painting
            switch (_orientation)
            {
            case Orientation.Horizontal:
                #region horizontal
                //horizontal stretching
                _grd.Transform = new Matrix(
                    (float)bandrct.Width + 2f, 0f, 0f, 1f, (float)bandrct.X - 1f, 0f);
                //fill band
                e.Graphics.FillRectangle(_checker, bandrct);
                e.Graphics.FillRectangle(_grd, bandrct);
                //draw position
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                position = bandrct.X + (bandrct.Width * _position) / 100;
                if (_fadetype == FadeType.External)                     //triangle select
                {
                    using (SolidBrush sld = new SolidBrush(forecolor))
                    {
                        e.Graphics.FillPolygon(sld, new Point[] {                              //upper triangle
                            new Point(position + 3, 0),
                            new Point(position, 5),
                            new Point(position - 3, 0)
                        });
                        e.Graphics.FillPolygon(sld, new Point[] {                              //lower triangle
                            new Point(position + 3, this.Height - 1),
                            new Point(position, this.Height - 6),
                            new Point(position - 3, this.Height - 1)
                        });
                    }
                }
                else                        //bracket select
                {
                    using (Pen pn = new Pen(forecolor))
                    {
                        e.Graphics.DrawLines(pn, new Point[] {                              //left bracket
                            new Point(position - 1, 0),
                            new Point(position - 3, 0),
                            new Point(position - 3, this.Height - 1),
                            new Point(position - 1, this.Height - 1)
                        });
                        e.Graphics.DrawLines(pn, new Point[] {                              //right bracket
                            new Point(position + 1, 0),
                            new Point(position + 3, 0),
                            new Point(position + 3, this.Height - 1),
                            new Point(position + 1, this.Height - 1)
                        });
                    }
                }

                #endregion
                break;

            case Orientation.Vertical:
                #region vertical
                //horizontal stretching
                //vertical stretching and rotating
                _grd.Transform = new Matrix(
                    0f, (float)bandrct.Width + 2f, 1f, 0f, 0f, (float)bandrct.Y + 1f);
                //fill band
                e.Graphics.FillRectangle(_checker, bandrct);
                e.Graphics.FillRectangle(_grd, bandrct);
                //draw position
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                position = bandrct.Y + (bandrct.Height * _position) / 100;
                if (_fadetype == FadeType.External)                     //triangle select
                {
                    using (SolidBrush sld = new SolidBrush(forecolor))
                    {
                        e.Graphics.FillPolygon(sld, new Point[] {                              //left triangle
                            new Point(0, position + 3),
                            new Point(5, position),
                            new Point(0, position - 3)
                        });
                        e.Graphics.FillPolygon(sld, new Point[] {                              //lower triangle
                            new Point(this.Width - 1, position + 3),
                            new Point(this.Width - 6, position),
                            new Point(this.Width - 1, position - 3)
                        });
                    }
                }
                else                        //bracket select
                {
                    using (Pen pn = new Pen(forecolor))
                    {
                        e.Graphics.DrawLines(pn, new Point[] {                              //left bracket
                            new Point(0, position - 1),
                            new Point(0, position - 3),
                            new Point(this.Width - 1, position - 3),
                            new Point(this.Width - 1, position - 1)
                        });
                        e.Graphics.DrawLines(pn, new Point[] {                              //right bracket
                            new Point(0, position + 1),
                            new Point(0, position + 3),
                            new Point(this.Width - 1, position + 3),
                            new Point(this.Width - 1, position + 1)
                        });
                    }
                }
                #endregion
                break;
            }
        }