Пример #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;

            if (!DesignMode)
            {
                g.Clear(this.BackColor);

                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                for (int i = 0; i < dotRects.Count; i++)
                {
                    if (i != dotRects.Count - 1)
                    {
                        g.FillEllipse(BrushCreator.CreateSolidBrush("#0"), dotRects[i]);
                    }
                    else
                    {
                        g.FillEllipse(BrushCreator.CreateSolidBrush("#1"), dotRects[i]);
                    }
                }
            }
            else
            {
                g.FillRectangle(BrushCreator.CreateSolidBrush("#0"), new Rectangle(0, 0, this.Width - 1, this.Height - 1));
            }
        }
Пример #3
0
        public ToogleButton()
        {
            _colors          = new ToogleButtonColors();
            _backgroundBrush = BrushCreator.CreateSolidBrush(_colors.Bg);
            _dotBrush        = BrushCreator.CreateSolidBrush(_colors.Dot);
            _borderPen       = PenCreator.Create(_colors.Border);


            DoubleBuffered = true;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

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

            var g = e.Graphics;

            string barColor   = null;
            string rangeColor = null;
            string dotColor   = null;

            if (!Enabled)
            {
                barColor   = Colors.BarDisabled;
                rangeColor = Colors.RangeDisabled;
                dotColor   = Colors.DotDisabled;
            }
            else if (isHovered)
            {
                barColor   = Colors.BarHovered;
                rangeColor = Colors.RangeHovered;
                dotColor   = Colors.DotHovered;
            }
            else
            {
                barColor   = Colors.Bar;
                rangeColor = Colors.Range;
                dotColor   = Colors.Dot;
            }

            // bar background
            g.FillRectangle(BrushCreator.CreateSolidBrush(barColor), barRect);

            // rangebar range
            if (value < secondValue)
            {
                g.FillRectangle(BrushCreator.CreateSolidBrush(rangeColor), rangeValue2Rect);
                g.FillRectangle(BrushCreator.CreateSolidBrush(barColor), rangeValue1Rect);
            }
            else
            {
                g.FillRectangle(BrushCreator.CreateSolidBrush(rangeColor), rangeValue1Rect);
                g.FillRectangle(BrushCreator.CreateSolidBrush(barColor), rangeValue2Rect);
            }

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.FillEllipse(BrushCreator.CreateSolidBrush(dotColor), dot1Rect);
            g.FillEllipse(BrushCreator.CreateSolidBrush(dotColor), dot2Rect);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
        }
Пример #5
0
        public TrackBar() : base()
        {
            maxValue = 100;
            minValue = 0;
            value    = 0;

            DoubleBuffered = true;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            //
            trackBgPen          = PenCreator.Create(Color.Black, BAR_HEIGHT);
            trackBgPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
            trackBgPen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;

            trackValuePen          = PenCreator.Create(Color.Black, BAR_HEIGHT);
            trackValuePen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
            trackValuePen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;

            dotBrush = BrushCreator.CreateSolidBrush();
        }
Пример #6
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);
        }