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);
                }
            }
        }
    }
}
相关推荐
lkbhua莱克瓦2419 小时前
进阶-索引4-使用规则
开发语言·数据库·笔记·sql·mysql·使用规则
未来之窗软件服务19 小时前
幽冥大陆(九十二 ) 封装 PHP HTTP 请求的 —东方仙盟练气期
开发语言·http·php·仙盟创梦ide·东方仙盟
毕设源码-钟学长19 小时前
【开题答辩全过程】以 基于JSP技术的健康信息网站的设计与实现为例,包含答辩的问题和答案
java·开发语言
时光追逐者19 小时前
一个基于 .NET 8 开源免费、高性能、低占用的博客系统
c#·.net·博客系统
AI追随者19 小时前
Python异步编程:深入理解asyncio核心原理与实战
开发语言·python·pycharm
醒过来摸鱼19 小时前
redisson可重入锁
java·开发语言
至为芯19 小时前
IP5330至为芯支持TYPE-C协议的3A充放电移动电源方案芯片
c语言·开发语言
tobias.b19 小时前
408真题解析-2009-12-计组-C语言整型提升-补码运算
c语言·开发语言·408考研·408真题·真题解析
dly_blog19 小时前
Composition API 设计思想(第11节)
开发语言·前端·javascript
superman超哥19 小时前
Rust 所有权与零成本抽象的关系:编译期优化的完美结合
开发语言·后端·rust·rust所有权·rust零成本抽象·编译期优化