Winform-自定义按钮_播放图标
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management.Instrumentation;
namespace MyContrl
{
/// <summary>
/// 播放按钮
/// </summary>
public partial class PlayButton : ToolStripButton
{
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
Graphics g = pevent.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias; // 抗锯齿,使边缘平滑
SolidBrush sb = new SolidBrush(Color.Red); // 默认红色
RectangleF rect = new RectangleF(5, 4, (this.Height / 2) + 2, (this.Height / 2) + 2); // 圆或方形
List<PointF> pointFs = new List<PointF>();
pointFs.Add(new PointF(6,5));
pointFs.Add(new PointF(6, this.Height-5));
pointFs.Add(new PointF((this.Height / 2)+4, this.Height / 2));
// 填充控件内部
if (this.Tag != null && this.Tag.ToString().Contains("1")) // 1为绿
{
sb = new SolidBrush(Color.Red);
g.FillRectangle(sb, rect);
}
else if (this.Tag != null && this.Tag.ToString().Contains("2")) // 1为红/黄
{
sb = new SolidBrush(Color.Green);
g.FillPolygon(sb, pointFs.ToArray());
}
else
{
sb = new SolidBrush(Color.Green);
g.FillPolygon(sb, pointFs.ToArray());
}
}
}
}
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/17307826.html
分类:
.Net-WinForm
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下