网站首页 > 技术文章 正文
绘制按钮颜色列表:
private List<Color> buttonColors; // 按钮颜色列表
private int activeButtonIndex = -1; // 激活的按钮索引
public _55l2()
{
InitializeComponent();
buttonColors = new List<Color>
{
Color.Green,
Color.Blue,
Color.Red,
Color.Yellow,
Color.Orange
};
}
绘制按钮扇形或甜甜圈
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
// 绘制按钮扇形
if (buttonColors.Count > 0)
{
float startAngle = -90;
float sweepAngle = 360f / buttonColors.Count;
for (int i = 0; i < buttonColors.Count; i++)
{
using (SolidBrush buttonBrush = new SolidBrush(buttonColors[i]))
{
if (i == activeButtonIndex)
{
g.FillPie(buttonBrush, rect, startAngle, sweepAngle);
}
else
{
g.FillPie(buttonBrush, rect, startAngle, sweepAngle - 1);
}
}
startAngle += sweepAngle;
}
}
// 绘制按钮扇形或甜甜圈
if (buttonColors.Count > 0)
{
float innerRectRadius = rect.Height/2/2-Width/2/8; // 调整甜甜圈中心的圆的大小
for (int i = 0; i < buttonColors.Count; i++)
{
using (SolidBrush buttonBrush = new SolidBrush(buttonColors[i]))
{
if (i == activeButtonIndex)
{
g.FillEllipse(buttonBrush, rect.X + innerRectRadius, rect.Y + innerRectRadius, rect.Width - 2 * innerRectRadius, rect.Height - 2 * innerRectRadius);
// 添加文本
string buttonText = (i + 1) + "号";
SizeF textSize = g.MeasureString(buttonText, new Font(Font.FontFamily, 100)); // 调整字体大小为10
PointF textPosition = new PointF(rect.X + (rect.Width - textSize.Width) / 2, rect.Y + (rect.Height - textSize.Height) / 2);
g.DrawString(buttonText, new Font(Font.FontFamily, 100), Brushes.Pink, textPosition); // 调整字体大小为10
}
}
}
引发按钮点击事件
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
float startAngle = -90;
float sweepAngle = 360f / buttonColors.Count;
for (int i = 0; i < buttonColors.Count; i++)
{
GraphicsPath buttonPath = new GraphicsPath();
buttonPath.AddPie(new Rectangle(0, 0, Width - 1, Height - 1), startAngle, sweepAngle);
if (buttonPath.IsVisible(e.Location))
{
activeButtonIndex = i;
Invalidate();
break;
}
startAngle += sweepAngle;
}
}
猜你喜欢
- 2024-11-12 C#-练习题 014(c#程序题及答案)
- 2024-11-12 C# 类型转换(c类型转换有哪三种形式)
- 2024-11-12 C#-无参数有返回值的方法 060(有参无返回值 c语言)
- 2024-11-12 C#中的值类型和引用类型(c# 引用类型)
- 2024-11-12 abelkhan中的rpc框架(rpc框架应用场景)
- 2024-11-12 C#编程零基础到入门学习-C# 值类型和引用类型(4-8)
- 2024-11-12 2.6 C#的常用关键字和预定义类型(c#预留关键字)
- 2024-11-12 C#_图片拖拽(c#窗体图片移动)
- 2024-11-12 数据类型 - C#入门教程(c#常见数据类型)
- 2024-11-12 C#中堆栈(Stack)和堆(Heap)的区别——第一部分
- 1507℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 505℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 484℃MySQL service启动脚本浅析(r12笔记第59天)
- 465℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 462℃启用MySQL查询缓存(mysql8.0查询缓存)
- 442℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 422℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 418℃MySQL server PID file could not be found!失败
- 最近发表
-
- netty系列之:搭建HTTP上传文件服务器
- 让deepseek教我将deepseek接入word
- 前端大文件分片上传断点续传(前端大文件分片上传断点续传怎么操作)
- POST 为什么会发送两次请求?(post+为什么会发送两次请求?怎么回答)
- Jmeter之HTTP请求与响应(jmeter运行http请求没反应)
- WAF-Bypass之SQL注入绕过思路总结
- 用户疯狂点击上传按钮,如何确保只有一个上传任务在执行?
- 二 计算机网络 前端学习 物理层 链路层 网络层 传输层 应用层 HTTP
- HTTP请求的完全过程(http请求的基本过程)
- dart系列之:浏览器中的舞者,用dart发送HTTP请求
- 标签列表
-
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- linux删除一个文件夹 (65)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)