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

            var g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            string bgColor     = null;
            string dotColor    = null;
            string borderColor = null;

            int maxHeight = this.Height - 1;
            int maxWidth  = this.Width - 1;

            if (!Enabled)
            {
                bgColor     = _colors.BgDisabled;
                borderColor = _colors.BorderDisabled;
                dotColor    = _colors.DotDisabled;
            }
            else if (isHovered)
            {
                bgColor     = _colors.BgHovered;
                borderColor = _colors.BorderHovered;
                dotColor    = _colors.DotHovered;
            }
            else if (Checked)
            {
                bgColor     = _colors.BgChecked;
                borderColor = _colors.BorderChecked;
                dotColor    = _colors.DotChecked;
            }
            else
            {
                bgColor     = _colors.Bg;
                borderColor = _colors.Border;
                dotColor    = _colors.Dot;
            }

            // bg
            var bgBrush = BrushCreator.CreateSolidBrush(bgColor);

            g.FillEllipse(bgBrush, new Rectangle(0, 0, maxHeight, maxHeight));
            g.FillRectangle(bgBrush, new RectangleF(maxHeight / 2, 0, maxWidth - maxHeight, maxHeight));
            g.FillEllipse(bgBrush, new Rectangle(maxWidth - maxHeight, 0, maxHeight, maxHeight));

            // border
            _borderPen.Color = ExColorTranslator.Get(borderColor);
            g.DrawArc(_borderPen, new Rectangle(0, 0, maxHeight, maxHeight), 90, 180);
            g.DrawLine(_borderPen, maxHeight / 2, 0, maxWidth - maxHeight / 2, 0);
            g.DrawLine(_borderPen, maxHeight / 2, maxHeight, maxWidth - maxHeight / 2, maxHeight);
            g.DrawArc(_borderPen, new Rectangle(maxWidth - maxHeight, 0, maxHeight, maxHeight), 270, 180);

            // dot
            g.FillEllipse(_dotBrush, isChecked ? onRect : offRect);

            // txt
            g.DrawString(Checked ? "On" : "Off", this.Font, _dotBrush, txtStatePosition);
        }
Пример #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var g = e.Graphics;

            string barBgColor    = null;
            string progressColor = null;

            if (!Enabled)
            {
                barBgColor    = ProgressBarColors.BarBackgoundDisabled;
                progressColor = ProgressBarColors.ProgressBackgoundDisabled;
            }
            else if (mouseOver)
            {
                barBgColor    = ProgressBarColors.BarBackgoundHovered;
                progressColor = ProgressBarColors.ProgressBackgoundHovered;
            }
            else
            {
                barBgColor    = ProgressBarColors.BarBackgound;
                progressColor = ProgressBarColors.ProgressBackgound;
            }

            // draw progress color
            pen.Color = ExColorTranslator.Get(barBgColor);
            g.DrawLine(pen, startPoint, endPoint);
            // draw progress value
            if (value > 0)
            {
                pen.Color = ExColorTranslator.Get(progressColor);
                g.DrawLine(pen, startPoint, valuePoint);
            }
        }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var g = e.Graphics;

            string barColor        = null;
            string trackValueColor = null;
            string dotColor        = null;

            if (!Enabled)
            {
                barColor        = Colors.BarDisabled;
                trackValueColor = Colors.TrackDisabled;
                dotColor        = Colors.DotDisabled;
            }
            else if (barHovered)
            {
                barColor        = Colors.BarHovered;
                trackValueColor = Colors.TrackHovered;
                dotColor        = Colors.DotHovered;
            }
            else
            {
                barColor        = Colors.Bar;
                trackValueColor = Colors.Track;
                dotColor        = Colors.Dot;
            }

            trackBgPen.Color    = ExColorTranslator.Get(barColor);
            trackValuePen.Color = ExColorTranslator.Get(trackValueColor);
            dotBrush.Color      = ExColorTranslator.Get(dotColor);

            // track bar
            g.DrawLine(
                trackBgPen,
                new PointF(viewport.Left, viewport.Y + viewport.Height / 2),
                new PointF(viewport.Right, viewport.Y + viewport.Height / 2));

            // value bar
            g.DrawLine(
                trackValuePen,
                new PointF(viewport.Left, viewport.Y + viewport.Height / 2),
                trackPoint);

            // dot 1
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.FillEllipse(dotBrush, dotRect);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
        }
Пример #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var g = e.Graphics;

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            string bgColor     = null;
            string textColor   = null;
            string borderColor = null;

            borderColor = SmallNofiticationColors.Border;
            if (_notifyType == NotifyType.Information)
            {
                bgColor   = SmallNofiticationColors.InformationBackground;
                textColor = SmallNofiticationColors.InformationText;
            }
            else if (_notifyType == NotifyType.Warning)
            {
                bgColor   = SmallNofiticationColors.WarningBackground;
                textColor = SmallNofiticationColors.WarningText;
            }
            else
            {
                bgColor   = SmallNofiticationColors.DangerBackground;
                textColor = SmallNofiticationColors.DangerText;
            }

            // background
            g.FillRectangle(BrushCreator.CreateSolidBrush(bgColor), ClientRectangle);
            // border
            g.DrawRectangle(PenCreator.Create(borderColor),
                            new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1));
            // content
            g.DrawImage(notifyImages[_notifyType], _iconBounds);
            TextRenderer.DrawText(e.Graphics, this.Title, _titleFont, _titleBounds, ExColorTranslator.Get(textColor), TextFormatFlags.NoPadding);
            TextRenderer.DrawText(e.Graphics, this.Text, this.Font, _textBounds, ExColorTranslator.Get(textColor), TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
        }
Пример #5
0
 public static SolidBrush CreateSolidBrush(string color = "#0")
 {
     return(new SolidBrush(ExColorTranslator.Get(color)));
 }
Пример #6
0
 /// <summary>
 /// Create pen with specified color
 /// </summary>
 /// <param name="color"></param>
 /// <returns></returns>
 public static Pen Create(string color = "#0", float lineWeight = 1f)
 {
     return(new Pen(ExColorTranslator.Get(color)));
 }