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);
                }
            }
        }
    }
}
相关推荐
水云桐程序员6 小时前
C++可以写手机应用吗
开发语言·c++·智能手机
测试员周周6 小时前
【AI测试智能体】为什么传统测试方法对智能体失效?
开发语言·人工智能·python·功能测试·测试工具·单元测试·测试用例
RSTJ_16256 小时前
PYTHON+AI LLM DAY THREETY-NINE
开发语言·人工智能·python
火星papa7 小时前
C# 阻塞队列(BlockingCollection)
c#·queue·阻塞队列
赏金术士7 小时前
Kotlin 从入门到进阶 之函数模块(核心基础)(二)
android·开发语言·kotlin
加号39 小时前
【Qt】 应用程序发布:依赖库拷贝与部署指南
开发语言·qt
('-')10 小时前
八股复习2:Java Array list和Linked list
java·开发语言
小黄人软件10 小时前
C++读写编辑CSV文件示例源码 用于数据导入导出,比Excel好使
开发语言·c++·excel
郭涤生10 小时前
C++各个版本的性能和安全性总结
开发语言·c++
wljy111 小时前
二、静态库的制作和使用
linux·c语言·开发语言·c++