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());
            }
        }
    }
}
posted @   ꧁执笔小白꧂  阅读(109)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示