Пример #1
0
            protected override void OnPaint(PaintEventArgs e)
            {
                e.Graphics.DrawLine(SystemPens.ControlDark, 0, 0, Width, 0);
                e.Graphics.DrawLine(SystemPens.ControlLightLight, 0, 1, Width, 1);
                if (_mouseIn)
                {
                    using (var brush = new SolidBrush(BackColor.Darken()))
                    {
                        e.Graphics.FillRectangle(brush, new Rectangle(0, 3, Width, Height - Padding.Vertical));
                    }
                }
                else
                {
                    using (var brush = new SolidBrush(BackColor.Darken(10)))
                    {
                        e.Graphics.FillRectangle(brush, new Rectangle(0, Height - Padding.Vertical + 2, Width, 1));
                    }
                }
                using (var brush = new SolidBrush(ForeColor))
                {
                    e.Graphics.FillPolygon(brush, GetTrianglePoints());
                }

                base.OnPaint(e);
            }
Пример #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            const int padding = 4;
            var       rect = Rectangle.Empty;
            var       rotflip = RotateFlipType.RotateNoneFlipNone;
            int       buttonX = 0, buttonY = 0;

            switch (Dock)
            {
            case DockStyle.Top:
                rect    = new Rectangle(padding + ButtonHeight, Height - RenderHandleWidth - 1, Width - padding - padding - ButtonHeight, RenderHandleWidth);
                rotflip = _hidden ? RotateFlipType.RotateNoneFlipNone : RotateFlipType.RotateNoneFlipY;
                buttonX = padding;
                buttonY = Height - HandleWidth;
                break;

            case DockStyle.Bottom:
                rect    = new Rectangle(padding + ButtonHeight, 1, Width - padding - padding - ButtonHeight, RenderHandleWidth);
                rotflip = !_hidden ? RotateFlipType.RotateNoneFlipNone : RotateFlipType.RotateNoneFlipY;
                buttonX = padding;
                break;

            case DockStyle.Left:
                rect    = new Rectangle(Width - RenderHandleWidth - 1, padding + ButtonHeight, RenderHandleWidth, Height - padding - padding - ButtonHeight);
                rotflip = _hidden ? RotateFlipType.Rotate90FlipX : RotateFlipType.Rotate90FlipNone;
                buttonY = padding;
                buttonX = Width - HandleWidth;
                break;

            case DockStyle.Right:
                rect    = new Rectangle(1, padding + ButtonHeight, RenderHandleWidth, Height - padding - padding - ButtonHeight);
                rotflip = !_hidden ? RotateFlipType.Rotate90FlipX : RotateFlipType.Rotate90FlipNone;
                buttonY = padding;
                break;
            }
            if (!rect.IsEmpty)
            {
                using (var b = new SolidBrush(BackColor.Darken(_hidden ? 10 : 40)))
                {
                    e.Graphics.FillRectangle(b, rect);
                }
                using (var cl = new Bitmap(_arrow))
                {
                    cl.RotateFlip(rotflip);
                    e.Graphics.DrawImage(cl, buttonX, buttonY);
                }
            }
        }
Пример #3
0
        private void PaintWarning(Graphics g, Rectangle surface, string warning)
        {
            const int MARGIN        = 2;
            SizeF     indicatorSize = new SizeF(30, 30);
            SizeF     warningSize   = g.MeasureString(warning, Font);
            SizeF     totalSize     = new SizeF(indicatorSize.Width + MARGIN + warningSize.Width, indicatorSize.Height);

            g.SmoothingMode = SmoothingMode.HighQuality;

            // Draw indicator.
            using (SolidBrush brush = new SolidBrush(Color.FromArgb(128, BackColor.Darken(.4f))))
            {
                g.FillEllipse(brush, new RectangleF(
                                  new PointF(
                                      (float)Math.Round(surface.Width / 2 - totalSize.Width / 2),
                                      (float)Math.Round(surface.Height / 2 - indicatorSize.Height / 2)
                                      ),
                                  indicatorSize
                                  ));
            }

            // Draw indicator text.
            using (Font font = new Font("Segoe UI", 18, FontStyle.Bold))
            {
                SizeF fontSize = g.MeasureString("?", font);

                g.DrawString(
                    "?",
                    font,
                    SystemBrushes.Control,
                    (float)Math.Round(surface.Width / 2 - totalSize.Width / 2 + indicatorSize.Width / 2 - fontSize.Width / 2 + 1.5),
                    (float)Math.Round(surface.Height / 2 - fontSize.Height / 2)
                    );
            }

            // Draw warning text.
            using (SolidBrush brush = new SolidBrush(Color.FromArgb(warningOpacity, ForeColor)))
            {
                g.DrawString(
                    warning,
                    Font,
                    brush,
                    (float)Math.Round(surface.Width / 2 + indicatorSize.Width - totalSize.Width / 2 + MARGIN),
                    (float)Math.Round(surface.Height / 2 - warningSize.Height / 2 + .5)
                    );
            }
        }
Пример #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignMode)
            {
                ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ForeColor, ButtonBorderStyle.Dashed);
            }

            if (Image == null)
            {
                return;
            }

            int imageX = Width / 2 - Image.Width / 2;
            int imageY = Height / 2 - Image.Height / 2;

            if (IsMouseOver || Selected)
            {
                // Draw mono image.
                if (!IsMouseDown || !Selected)
                {
                    e.Graphics.DrawImageMono(Image, BackColor.Darken(.2f), imageX, imageY);
                }

                // Draw filled background.
                using (SolidBrush brush = new SolidBrush(
                           Color.FromArgb(
                               Selected ?
                               IsMouseOver ? 128 : 26 :
                               IsMouseDown ? 192 : 64,
                               SystemColors.Highlight
                               )
                           ))
                {
                    e.Graphics.FillRectangle(brush, ClientRectangle);
                }

                // Draw border.
                ControlPaint.DrawBorder(e.Graphics, ClientRectangle, SystemColors.Highlight, ButtonBorderStyle.Solid);
            }

            int offset = IsMouseOver && !IsMouseDown && !Selected ? 1 : 0;

            e.Graphics.DrawImageTranslucent(Image, Selected ? 1 : .75f, imageX - offset, imageY - offset);
        }
Пример #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (Parent != null)
            {
                g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle);
            }

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Rectangle backgroundRect = new Rectangle(
                ClientRectangle.X,
                ClientRectangle.Y,
                ClientRectangle.Width - 1,
                ClientRectangle.Height - 1);

            if (FillBackground)
            {
                if (!_isSelected)
                {
                    if (RadioButtonFlatStyle)
                    {
                        LinearGradientBrush gradient = new LinearGradientBrush(backgroundRect, BackColor.Lighten(5), BackColor.Darken(25), LinearGradientMode.Vertical);
                        g.FillPath(gradient, ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(BackColor), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }

                    if (_useDarckenColorForBorder)
                    {
                        g.DrawPath(new Pen(BackColor.Darken(80), 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.DrawPath(new Pen(BorderColor, 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                }
                else
                {
                    if (RadioButtonFlatStyle)
                    {
                        LinearGradientBrush gradient = new LinearGradientBrush(backgroundRect, BackColor.Lighten(30), BackColor.Lighten(15), LinearGradientMode.Vertical);
                        g.FillPath(gradient, ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(BackColor.Lighten(30)), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }

                    if (_useDarckenColorForBorder)
                    {
                        g.DrawPath(new Pen(BorderColor.Lighten(20), 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                    else
                    {
                        g.DrawPath(new Pen(BorderColor, 1), ExtendedForms.RoundedRect(backgroundRect, BorderRadius));
                    }
                }
            }

            int        dotDiameter = ThumbRadius;
            int        thumbY      = ClientRectangle.Height / 2 - dotDiameter / 2 - 1;
            RectangleF innerRect   = new RectangleF(Padding.Left + Spacing, thumbY, dotDiameter, dotDiameter);
            int        textX       = ( int )innerRect.Left + ( int )innerRect.Width + Spacing;


            SolidBrush thumbBackBrush = null;
            Pen        thumbBorderPen = new Pen(ThumbColor, 2);
            SolidBrush thumbDotBrush  = new SolidBrush(ThumbColor);

            if (_isSelected)
            {
                thumbBackBrush = _whiteBrush;
                thumbBorderPen = (RadioButtonFlatStyle) ?
                                 thumbBorderPen = new Pen(BackColor.Darken(120), 2) :
                                                  thumbBorderPen = new Pen(ThumbColor, 2);
            }
            else
            {
                thumbBackBrush = _whiteBrush;
                thumbBorderPen = (RadioButtonFlatStyle) ?
                                 thumbBorderPen = new Pen(BackColor.Darken(130), 2) :
                                                  thumbBorderPen = new Pen(ThumbColor, 2);
            }

            int count = (Checked || _isSelected) ? 2 : 1;

            for (int i = 0; i < count; i++)
            {
                if (RoundedThumb)
                {
                    g.FillEllipse(((Checked || _isSelected) && i > 0) ? thumbDotBrush : thumbBackBrush, innerRect);
                    g.DrawEllipse(thumbBorderPen, innerRect);
                }
                else
                {
                    g.FillRectangle(thumbBackBrush, innerRect);
                    g.DrawRectangle(thumbBorderPen, innerRect.X, innerRect.Y, innerRect.Width, innerRect.Height);
                }

                innerRect.Inflate(-4, -4);
            }


            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Near;
            sf.FormatFlags   = StringFormatFlags.NoWrap;

            innerRect = new RectangleF(textX, 1, ClientRectangle.Width - 1 - dotDiameter - 2, ClientRectangle.Height - 3);

            SolidBrush textBrush = (ForeColor == Color.Black) ? _blackBrush : new SolidBrush(ForeColor);

            g.DrawString(Text, Font, textBrush, innerRect, sf);
        }