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);
                }
            }
        }
    }
}
相关推荐
长安第一美人8 小时前
C 语言可变参数(...)实战:从 logger_print 到通用日志函数
c语言·开发语言·嵌入式硬件·日志·工业应用开发
Larry_Yanan8 小时前
Qt多进程(一)进程间通信概括
开发语言·c++·qt·学习
superman超哥8 小时前
仓颉语言中基本数据类型的深度剖析与工程实践
c语言·开发语言·python·算法·仓颉
csdn_aspnet8 小时前
浅谈 C# 与 Data URI
c#
不爱吃糖的程序媛8 小时前
Ascend C开发工具包(asc-devkit)技术解读
c语言·开发语言
bu_shuo8 小时前
MATLAB奔溃记录
开发语言·matlab
你的冰西瓜9 小时前
C++标准模板库(STL)全面解析
开发语言·c++·stl
徐先生 @_@|||9 小时前
(Wheel 格式) Python 的标准分发格式的生成规则规范
开发语言·python
利剑 -~9 小时前
jdk源码解析
java·开发语言
烛阴9 小时前
C# 正则表达式:量词与锚点——从“.*”到精确匹配
前端·正则表达式·c#