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);
                }
            }
        }
    }
}
相关推荐
Behavior31 分钟前
Unity 手游动态更换 App 图标 — Android 与 iOS 双端技术方案
c#·unity3d·游戏开发
周杰伦fans1 小时前
构建真正智能的CAD AI绘图代理
开发语言·人工智能·c#
zhanghaha13143 小时前
Python进阶教程:35_PyQt (保姆级零基础教程)
开发语言·python·pyqt
释厄6233 小时前
多黑洞具现论·物理/生物/金融三域显化·虚拟宇宙黑洞·奇点=0 圆圈
开发语言·数据结构·人工智能·程序人生·安全威胁分析
UIU1144 小时前
递归算法与汉诺塔
c++·学习·算法·c#·递归
Fruit_Caller5 小时前
static
开发语言·c++
CSharp精选营10 小时前
我用 ASP.NET Core 做了个水稻病虫害检查系统
c#·毕业设计·.net core·码农刚子
唐青枫10 小时前
我用 C# 开发了一款电子发票自动整理工具
c#·.net
下页、再停留10 小时前
【C#桌面客户端系列学习-2】在原来窗口基础上打开新窗口
c#·visual studio
Behavior10 小时前
Unity 手游 iOS Deep Link 唤醒全流程:从 URL Scheme / Universal Links 到 C# 层参数投递
c#·unity3d·游戏开发