当前位置: 首页 > news >正文

C# Winform .net6自绘的圆形进度条

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;namespace Net6_GeneralUiWinFrm
{public class CircularProgressBar : Control{private int progress = 0;private int borderWidth = 20; // 增加的边框宽度public int Progress{get { return progress; }set{progress = Math.Max(0, Math.Min(100, value)); // 确保进度值在0到100之间Invalidate(); // Causes the control to be redrawn}}protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;// Draw background circleusing (Pen pen = new Pen(Color.LightGray, borderWidth)){pen.DashStyle = DashStyle.Dot; // 设置点状线条e.Graphics.DrawEllipse(pen, borderWidth / 2, borderWidth / 2, this.Width - borderWidth, this.Height - borderWidth);}// Draw progress arcusing (Pen pen = new Pen(Color.LightGreen, borderWidth)) //lightgreen{pen.DashStyle = DashStyle.Solid; // 进度使用实线// Calculate sweep anglefloat sweepAngle = (360f * progress) / 100f;e.Graphics.DrawArc(pen, borderWidth / 2, borderWidth / 2, this.Width - borderWidth, this.Height - borderWidth, -90, sweepAngle);}// Draw progress textstring progressText = $"{progress}%";using (Font font = new Font("Arial", 12))using (Brush brush = new SolidBrush(Color.Black)){SizeF textSize = e.Graphics.MeasureString(progressText, font);// Calculate text positionPointF textPoint = new PointF((this.Width - textSize.Width) / 2, (this.Height - textSize.Height) / 2);e.Graphics.DrawString(progressText, font, brush, textPoint);}}}
}

http://www.lryc.cn/news/302192.html

相关文章:

  • Git基本操作(超详细)
  • 【AGI视频】Sora的奇幻之旅:未来影视创作的无限可能
  • Docker部署nginx
  • C++Qt——自定义信号与槽
  • 提高项目的性能和响应速度的方法
  • QT学习事件
  • 第13章 网络 Page818 UDP(和TCP的比较)
  • EMQX Enterprise 5.4 发布:OpenTelemetry 分布式追踪、OCPP 网关、Confluent 集成支持
  • 记录 | C++ cout.setf(ios::fixed)
  • Eclipse 创建 Hello World 工程
  • 【前端工程化面试题】vite热更新原理
  • 【leetcode】判断二叉树是否完全二叉树
  • Java多线程系列——内存模型JMM
  • 深入理解 Vue3 中的 setup 函数
  • 【QT+QGIS跨平台编译】之三十六:【RasterLite2+Qt跨平台编译】(一套代码、一套框架,跨平台编译)
  • java面试题:分布式和微服务的区别
  • GO语言的变量与常量
  • java面试多线程篇
  • Anaconda + VS Code 的安装与使用
  • Python爬虫html网址实战笔记
  • C++ 调用js 脚本
  • Vscode python pyside6 制作视频播放器
  • 纯前端低代码平台demo,vue框架,nodejs,简单的pm2纯前端部署实践
  • 致创新者:聚焦目标,而非问题
  • javaSE和javaEE区别
  • 安装VMware+安装Linux
  • session和cookie理解
  • Springboot医院信息管理系统源码 带电子病历和LIS Saas应用+前后端分离+B/S架构
  • LeetCode.589. N 叉树的前序遍历
  • C++ Webserver从零开始:配置环境(九)——下载github的项目进行测试