c#绘制渐变色的Led

项目场景:

c#绘制渐变色的button


c 复制代码
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;

namespace WindowsFormsApp2
{
    public class GradientCircle : UserControl
    {
        public GradientCircle()
        {
            this.Size = new Size(circleSize, circleSize);
            this.Paint += new PaintEventHandler(GradientCircleForm_Paint);
            //this.Click += GradientCircleForm_Click;
        }

       
        private double _scale;
        int circleSize = 300, InitialSize = 300;
        [Category("自定义")]
        public double OverrideScale
        {
            set
            {
                circleSize = (int)(_scale * InitialSize);
                this.Size = new Size(circleSize, circleSize);
                _scale = value;    
                this.Invalidate();
            }
        }



        private Color _clrGradientCircle=Color.Green;
        [Category("自定义")]
        public Color ColorGradientCircle
        {
            get { 
                return _clrGradientCircle; 
            }
            set {
                _clrGradientCircle = value; 
            Invalidate();
            }
        }
        private void GradientCircleForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle circleRect = new Rectangle(
                (this.ClientSize.Width - circleSize) / 2,
                (this.ClientSize.Height - circleSize) / 2,
                circleSize,
                circleSize);
            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddEllipse(circleRect);
                using (PathGradientBrush brush = new PathGradientBrush(path))
                {
                    // 设置中心颜色
                    brush.CenterColor = Color.White;
                    // 边缘颜色可以是多种颜色
                    Color[] surroundColors = new Color[] { _clrGradientCircle };
                    brush.SurroundColors = surroundColors;
                    g.FillPath(brush, path);
                }
            }
        }
    }
}
相关推荐
源代码•宸4 分钟前
C++高频知识点(二十)
开发语言·c++·经验分享·epoll·拆包封包·名称修饰
阿巴~阿巴~15 分钟前
字节:计算机存储单位
c语言·开发语言
freed_Day24 分钟前
人工智能与机器学习基本概念知识入门
开发语言·人工智能·python·机器学习
TS的美梦24 分钟前
ROGUE: 【张院士团队R包】一种基于熵的用于评估单细胞群体纯度的度量标准
开发语言·r语言
Waitind_1 小时前
Python数据分析常规步骤整理
开发语言·python·数据分析
蓝点lilac1 小时前
C# WPF 内置解码器实现 GIF 动图控件
c#·.net·wpf·图像
静谧之心2 小时前
分层架构下的跨层通信:接口抽象如何解决反向调用
java·开发语言·设计模式·架构·golang·k8s·解耦
摸鱼一级选手2 小时前
Java 集合框架深层原理:不止于 “增删改查”
java·开发语言·后端
jie*2 小时前
小杰python高级(one day)——线性代数
开发语言·python
唐青枫2 小时前
别再用 Thread 了!掌握 C#.NET Task 异步编程的正确打开方式
c#·.net