コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Text = IsSimple ? "" : $"{IndicatorText} {_value.ToString("F1")}{AdditionalText}";

            var path = new GraphicsPath();

            if (IsSimple)
            {
                path.AddPolygon(new[] {
                    new PointF(0, 0),
                    new PointF(Width - 1, Height / 2.0F),
                    new PointF(0, Height - 1),
                });
            }
            else
            {
                path.AddPolygon(new[] {
                    new PointF(0, 0),
                    new PointF(Width - Height, 0),
                    new PointF(Width - 1, Height / 2.0F),
                    new PointF(Width - Height, Height - 1),
                    new PointF(0, Height - 1),
                });
            }

            using (var pen = new Pen(BorderColor, 1))
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                e.Graphics.DrawPath(pen, path);
            }

            Region = GraphicsUtilities.GetRegionForPath(path);
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var handleRectangleRadius = HandleHeight / 4;
            var textRectangleRadius   = HandleHeight / 2;

            valueLabel.Text     = $"{_value.ToString("F1")}{AdditionalText}";
            valueLabel.Location = new Point(HandleWidth + textRectangleRadius, 1);
            valueLabel.Size     = new Size(Width - HandleWidth - 2 * textRectangleRadius, Height - 2);

            var handleRectangle = new RectangleF(0, Height / 2.0F - HandleHeight / 2.0F, HandleWidth, HandleHeight);
            var textRectangle   = new Rectangle(HandleWidth, 0, Width - HandleWidth, Height);
            var handlePath      = GraphicsUtilities.CreateRoundedRectanglePath(handleRectangle, handleRectangleRadius);
            var textPath        = GraphicsUtilities.CreateRoundedRectanglePath(textRectangle, textRectangleRadius);

            var graphics = e.Graphics;

            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            using (var brush = new SolidBrush(BackColor))
            {
                graphics.FillPath(brush, handlePath);
                graphics.FillPath(brush, textPath);
            }
            using (var pen = new Pen(BorderColor))
            {
                graphics.DrawPath(pen, handlePath);
                graphics.DrawPath(pen, textPath);
            }
            using (var brush = new SolidBrush(BackColor))
            {
                var rect = handleRectangle;
                rect.Inflate(2, -1);
                rect.X += 3;
                graphics.FillRectangle(brush, rect);
            }

            var region = GraphicsUtilities.GetRegionForPath(handlePath);

            region.Union(GraphicsUtilities.GetRegionForPath(textPath));
            Region = region;
        }