protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

//          BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
//          BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
//          Graphics g = myBuffer.Graphics;

            Graphics g = e.Graphics;

            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;          //高像素偏移质量
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = CompositingQuality.HighQuality;

            g.Clear(this.BackColor);


            Color clr1 = Color.FromArgb(235, 242, 252);
            Color clr2 = Color.FromArgb(235, 242, 252);

            for (int i = SelectedIndex + 1; i < _gpBtnArr.Count; i++)
            {
                LinearGradientBrush bsh = new LinearGradientBrush(_gpBtnArr[i].BtnRect, clr1, clr2, 90f);
                g.FillPath(bsh, _gpBtnArr[i].BtnPath);
            }

            if (SelectedIndex > -1)
            {
                clr1 = Color.FromArgb(21, 166, 251);
                clr2 = CommonGraphic.ColorOffset(clr1, -0.1f);

                for (int i = 0; i <= SelectedIndex; i++)
                {
                    LinearGradientBrush bsh = new LinearGradientBrush(_gpBtnArr[i].BtnRect, clr1, clr2, 90f);
                    g.FillPath(bsh, _gpBtnArr[i].BtnPath);
                }
            }

            using (Pen pen = new Pen(Color.FromArgb(91, 159, 238)))
            {
                foreach (var btn in _gpBtnArr)
                {
                    g.DrawPath(pen, btn.BtnPath);
                }
            }

            TextRenderer.DrawText(g,
                                  MicroSteps.ToString(),
                                  this.Font,
                                  _txtRect,
                                  Color.Black,
                                  TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);

//          myBuffer.Render(e.Graphics);  //呈现图像至关联的Graphics
//          myBuffer.Dispose();
//          g.Dispose();
        }
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            //	base.OnPaintBackground(pevent);	//绘制按钮背景,透明效果

            Graphics g = pevent.Graphics;

            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;          //高像素偏移质量
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = CompositingQuality.HighQuality;


            if (_path == null)
            {
                _path = CommonGraphic.CreateRoundRectPath(ClientRectangle, _OffsetX, _OffsetY);
            }

            ////////////////////////////////////////绘制控件背景色/////////////////////////////////////////
            Color colorUp   = Color.FromArgb(69, 162, 217);
            Color colorDown = Color.FromArgb(68, 161, 218);

            switch (_controlState)
            {
            case ControlState.Hover:
                colorUp   = CommonGraphic.ColorOffset(colorUp, 0.2f);
                colorDown = CommonGraphic.ColorOffset(colorDown, 0.2f);
                break;

            case ControlState.Pressed:
                colorUp   = CommonGraphic.ColorOffset(colorUp, -0.2f);
                colorDown = CommonGraphic.ColorOffset(colorDown, -0.2f);
                break;

            default:
                break;
            }

            LinearGradientBrush lgb = new LinearGradientBrush(ClientRectangle,
                                                              colorUp,
                                                              colorDown,
                                                              90f);

            g.FillPath(lgb, _path);

            ////////////////////////////////////////绘制空间边框/////////////////////////////////////////
            Color borderColor = CommonGraphic.ColorOffset(colorDown, -0.2f);
            Pen   pen         = new Pen(borderColor, 1.0f);

            g.DrawPath(pen, _path);

            pen.Color = CommonGraphic.ColorOffset(colorDown, 0.1f);
            g.DrawPath(pen, _borderPath);

            ////////////////////////////////////////绘制文字/////////////////////////////////////////
            Rectangle txtRect = ClientRectangle;

            if (this.BackgroundImage != null)
            {
                float height = this.ClientRectangle.Height * 0.8f;
                float width  = height * this.BackgroundImage.Width / this.BackgroundImage.Height;

                g.DrawImage(this.BackgroundImage, 5, (ClientRectangle.Height - height) / 2.0f, width, height);

                txtRect.Offset((int)height, 0);
                txtRect.Width -= (int)height;
            }
            TextRenderer.DrawText(g,
                                  this.Text,
                                  this.Font,
                                  txtRect,
                                  this.ForeColor,
                                  TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
        }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
//          BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
//          BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
//          Graphics g = myBuffer.Graphics;

            Graphics g = e.Graphics;

            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;          //高像素偏移质量
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = CompositingQuality.HighQuality;


            g.Clear(this.BackColor);

            Rectangle rect = ClientRectangle;

            if (_totalPath == null)
            {
                _totalPath = CommonGraphic.CreateRoundRectPath(rect, OffsetX, OffsetY);
            }

            Color colorDown = BackColor;
            Color colorUp   = BackColor;

            //绘制控件背景色
            SolidBrush lgb = new SolidBrush(BackColor);

            g.FillPath(lgb, _totalPath);

            if (_gpBtnArr.Count > 0)
            {
                Pen splitPenMain = new Pen(CommonGraphic.ColorOffset(BackColor, -0.2f), 1f);
                Pen splitPenSub  = new Pen(CommonGraphic.ColorOffset(BackColor, 0.2f), 1f);

                Color pressedColor = CommonGraphic.ColorOffset(BackColor, -0.2f);

                Image bkImage = null;

                for (int i = 0; i < _gpBtnArr.Count; i++)
                {
                    bkImage = _gpBtnArr[i].BackgroundImage;

                    if (_gpBtnArr[i].Pressed)
                    {
                        using (SolidBrush btnbsh = new SolidBrush(pressedColor))
                        {
                            g.FillPath(btnbsh, _gpBtnArr[i].BtnPath);
                        }

                        if (_gpBtnArr[i].SelectedBKImage != null)
                        {
                            bkImage = _gpBtnArr[i].SelectedBKImage;
                        }
                    }
                    else if (_gpBtnArr[i].MouseHover)
                    {
                        using (SolidBrush btnbsh = new SolidBrush(CommonGraphic.ColorOffset(this.BackColor, -0.05f) /*CommonGraphic.ColorOffset(Color.White, -240, 0, 0, 0)*/))
                        {
                            g.FillPath(btnbsh, _gpBtnArr[i].BtnPath);
                        }
                    }

                    if (i < _gpBtnArr.Count - 1 &&
                        i != this.MouseHoverIndex - 1 &&
                        i != this.MouseHoverIndex &&
                        i != this.PressedIndex - 1 &&
                        i != this.PressedIndex)
                    {
                        CommonGraphic.DrawLine(g, splitPenMain,
                                               _gpBtnArr[i].BtnRect.Right,
                                               _gpBtnArr[i].BtnRect.Top + 6f,
                                               _gpBtnArr[i].BtnRect.Right,
                                               _gpBtnArr[i].BtnRect.Bottom - 6f);

                        CommonGraphic.DrawLine(g, splitPenSub,
                                               _gpBtnArr[i].BtnRect.Right + 1f,
                                               _gpBtnArr[i].BtnRect.Top + 6f,
                                               _gpBtnArr[i].BtnRect.Right + 1f,
                                               _gpBtnArr[i].BtnRect.Bottom - 6f);
                    }

                    Rectangle txtRect = Rectangle.Round(_gpBtnArr[i].BtnRect);

                    if (bkImage != null)
                    {
                        SizeF fontSize = g.MeasureString(_gpBtnArr[i].Text, this.Font);

                        float height    = (float)Math.Round(_gpBtnArr[i].BtnRect.Height * 0.76f, 1);                                    //图片高度;
                        float width     = (float)Math.Round(height * bkImage.Width / bkImage.Height);                                   //图片宽度;
                        float textWidth = fontSize.Width * 1.3f;                                                                        //文字宽度;

                        float imageLeftOffset = (_gpBtnArr[i].BtnRect.Width - (width + textWidth)) / 2f;                                //图片相对于按钮左边偏移

                        g.DrawImage(bkImage,
                                    _gpBtnArr[i].BtnRect.Left + imageLeftOffset,
                                    _gpBtnArr[i].BtnRect.Top + (_gpBtnArr[i].BtnRect.Height - height) / 2.0f,
                                    width, height);

                        txtRect.Offset((int)(imageLeftOffset + width), 0);
                        txtRect.Width = (int)textWidth;
                    }

                    TextRenderer.DrawText(g,
                                          _gpBtnArr[i].Text,
                                          this.Font,
                                          txtRect,
                                          this.ForeColor,
                                          TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                }
            }

//          myBuffer.Render(e.Graphics);  //呈现图像至关联的Graphics
//          myBuffer.Dispose();
//          g.Dispose();
        }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;          //高像素偏移质量
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = CompositingQuality.HighQuality;

            g.Clear(this.BackColor);

            Rectangle rect = ClientRectangle;

            if (_totalPath == null)
            {
                _totalPath = new GraphicsPath();

                _totalPath.Reset();
                _totalPath.AddRectangle(ClientRectangle);
            }

            SolidBrush bsh = new SolidBrush(BackColor);

            g.FillPath(bsh, _totalPath);

            if (_gpBtnArr.Count > 0)
            {
                Pen splitPenUp   = new Pen(CommonGraphic.ColorOffset(BackColor, -0.3f), 1.5f);
                Pen splitPenDown = new Pen(CommonGraphic.ColorOffset(BackColor, 0.2f), 1.5f);

                Image bkImage = null;

                for (int i = 0; i < _gpBtnArr.Count; i++)
                {
                    Color     txtColor = Color.White;
                    Rectangle txtRect  = Rectangle.Round(_gpBtnArr[i].BtnRect);

                    bkImage = _gpBtnArr[i].BackgroundImage;

                    if (_gpBtnArr[i].Selected)
                    {
                        txtColor = Color.White;

                        if (_gpBtnArr[i].SelectedBKImage != null)
                        {
                            bkImage = _gpBtnArr[i].SelectedBKImage;
                        }

                        SolidBrush btnbsh = new SolidBrush(SelectedColor);
                        g.FillPath(btnbsh, _gpBtnArr[i].BtnPath);

                        Color spiltLine = CommonGraphic.ColorOffset(SelectedColor, -0.3f);

                        Pen linePen = new Pen(spiltLine);
                        g.DrawLine(linePen,
                                   _gpBtnArr[i].BtnRect.Right,
                                   _gpBtnArr[i].BtnRect.Top + 10.0f,
                                   _gpBtnArr[i].BtnRect.Right,
                                   _gpBtnArr[i].BtnRect.Bottom - 10.0f);
                    }
                    else if (_gpBtnArr[i].MouseHover)
                    {
                        txtRect.Inflate(-5, -5);
                        txtRect.Offset(5, 5);
                    }

                    if (i != this.SelectedIndex - 1 &&
                        i != this.SelectedIndex)
                    {
                        CommonGraphic.DrawLine(g, splitPenUp,
                                               _gpBtnArr[i].BtnRect.Left + 2f,
                                               _gpBtnArr[i].BtnRect.Bottom,
                                               _gpBtnArr[i].BtnRect.Right - 2f,
                                               _gpBtnArr[i].BtnRect.Bottom);

                        CommonGraphic.DrawLine(g, splitPenDown,
                                               _gpBtnArr[i].BtnRect.Left + 2f,
                                               _gpBtnArr[i].BtnRect.Bottom + 1,
                                               _gpBtnArr[i].BtnRect.Right - 2f,
                                               _gpBtnArr[i].BtnRect.Bottom + 1);
                    }

                    if (bkImage != null)
                    {
                        float height = _gpBtnArr[i].BtnRect.Height * 0.5f;
                        float width  = height * bkImage.Width / bkImage.Height;

                        g.DrawImage(bkImage,
                                    _gpBtnArr[i].BtnRect.Left + (_gpBtnArr[i].BtnRect.Height - width) / 2.0f,
                                    _gpBtnArr[i].BtnRect.Top + (_gpBtnArr[i].BtnRect.Height - height) / 2.0f,
                                    width, height);

                        txtRect.Offset((int)_gpBtnArr[i].BtnRect.Height, 0);
                        txtRect.Width -= (int)_gpBtnArr[i].BtnRect.Height;
                    }

                    TextRenderer.DrawText(g,
                                          _gpBtnArr[i].Text,
                                          this.Font,
                                          txtRect,
                                          txtColor,
                                          /*TextFormatFlags.HorizontalCenter | */ TextFormatFlags.VerticalCenter);

                    if (_highLightDic.ContainsKey(i))
                    {
                        if (_highLightDic[i] > 0)
                        {
                            Rectangle numRect = new Rectangle();
                            numRect.X      = (int)_gpBtnArr[i].BtnRect.Right - 35;
                            numRect.Y      = (int)_gpBtnArr[i].BtnRect.Top + (int)_gpBtnArr[i].BtnRect.Height / 2 - 15;
                            numRect.Width  = 30;
                            numRect.Height = 30;

                            bsh.Color = Color.Red;
                            g.FillEllipse(bsh, numRect);

                            numRect.Offset(0, -2);
                            TextRenderer.DrawText(g,
                                                  _highLightDic[i].ToString(),
                                                  _numFont,
                                                  numRect,
                                                  Color.White,
                                                  TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                        }
                    }
                }

                if (EnableDisplayTime)
                {
                    TextRenderer.DrawText(g,
                                          DateTime.Now.ToString(TimeFormat),
                                          this.TimeFont,
                                          _timeRect,
                                          Color.White,
                                          TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                }
            }
        }