protected override void OnPaint(PaintEventArgs pevent)
        {
            Graphics g = pevent.Graphics;

            g.Clear(Parent.BackColor);
            g.SmoothingMode     = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            if (ShadowSize > 0)
            {
                GlobalHelpers.DrawDownFade(g, new Rectangle(-1, Height - ShadowSize, Width + 1, ShadowSize),
                                           ShadowColor);
            }
            using (
                SolidBrush backColorBrush = new SolidBrush(BackColor),
                foreColorBrush = new SolidBrush(ForeColor),
                overlayBrush = new SolidBrush(_overlapColor))
                using (Pen borderPen = new Pen(BorderColor), foreColorPen = new Pen(ForeColor))
                {
                    Rectangle clippedBounds = new Rectangle(-1, -1, Width + 2, Height + 2 - ShadowSize);
                    g.SetClip(new Rectangle(0, 0, Width, Height - ShadowSize + 1));
                    g.FillRectangle(backColorBrush, clippedBounds);
                    g.DrawRectangle(borderPen, 0, 0, Width - 1, Height - ShadowSize);
                    g.FillRectangle(overlayBrush, clippedBounds);
                    g.DrawString(Text, Font, foreColorBrush, 10, 7);
                    SizeF stringSize = g.MeasureString(Text, Font);
                    g.DrawLine(foreColorPen, 10, stringSize.Height + 9, stringSize.Width + 10, stringSize.Height + 9);
                }
        }
Exemple #2
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            Graphics g = pevent.Graphics;

            g.Clear(Parent.BackColor);
            g.SmoothingMode     = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            if (ShadowSize > 0)
            {
                GlobalHelpers.DrawDownFade(g, new Rectangle(-1, Height - ShadowSize, Width + 1, ShadowSize),
                                           ShadowColor);
            }
            using (
                SolidBrush backColorBrush = new SolidBrush(BackColor),
                foreColorBrush = new SolidBrush(ForeColor),
                overlayBrush = new SolidBrush(_overlapColor))
                using (Pen borderPen = new Pen(BorderColor))
                {
                    Rectangle clippedBounds = new Rectangle(-1, -1, Width + 2, Height + 2 - ShadowSize);
                    g.SetClip(new Rectangle(0, 0, Width, Height - ShadowSize + 1));
                    g.FillRectangle(backColorBrush, clippedBounds);
                    g.DrawRectangle(borderPen, 0, 0, Width - 1, Height - ShadowSize);
                    g.FillRectangle(overlayBrush, clippedBounds);
                    SizeF  stringSize   = g.MeasureString(Text, Font);
                    PointF textPosition = new PointF(0, 0);
                    if (TextAlign == ContentAlignment.MiddleCenter)
                    {
                        textPosition = new PointF((Width - stringSize.Width) / 2,
                                                  (Height - stringSize.Height - ShadowSize) / 2);
                    }
                    else if (TextAlign == ContentAlignment.MiddleLeft)
                    {
                        textPosition = new PointF(3, (Height - stringSize.Height - ShadowSize) / 2);
                    }
                    else if (TextAlign == ContentAlignment.MiddleRight)
                    {
                        textPosition = new PointF(Width - 4 - stringSize.Width,
                                                  (Height - stringSize.Height - ShadowSize) / 2);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    g.DrawString(Text, Font, foreColorBrush, textPosition);
                }
        }