WinForm-扁平化设计之 Panel样式重绘-圆角(还未实现)
/// <summary> /// 重写Panel-还未实现圆角功能 /// </summary> public class RoundPanel : Panel { private int mMatrixRound = 8; private Color mBack; public Color Back { get { return mBack; } set { if (value == null) { mBack = Control.DefaultBackColor; } else { mBack = value; } base.Refresh(); } } public int MatrixRound { get { return mMatrixRound; } set { mMatrixRound = value; base.Refresh(); } } private GraphicsPath CreateRound(Rectangle rect, int radius) { GraphicsPath roundRect = new GraphicsPath(); //顶端 roundRect.AddLine(rect.Left + radius - 1, rect.Top - 1, rect.Right - radius, rect.Top - 1); //右上角 roundRect.AddArc(rect.Right - radius, rect.Top - 1, radius, radius, 270, 90); //右边 roundRect.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius); //右下角 roundRect.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90); //底边 roundRect.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom); //左下角 roundRect.AddArc(rect.Left - 1, rect.Bottom - radius, radius, radius, 90, 90); //左边 roundRect.AddLine(rect.Left - 1, rect.Top + radius, rect.Left - 1, rect.Bottom - radius); //左上角 roundRect.AddArc(rect.Left - 1, rect.Top - 1, radius, radius, 180, 90); return roundRect; } protected override void OnPaint(PaintEventArgs e) { int width = base.Width - base.Margin.Left - base.Margin.Right; int height = base.Height - base.Margin.Top - base.Margin.Bottom; Rectangle rec = new Rectangle(base.Margin.Left, base.Margin.Top, width, height); GraphicsPath round = CreateRound(rec, mMatrixRound); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillPath((Brush)(new SolidBrush(mBack)), round); } protected override void OnResize(EventArgs eventargs) { base.Refresh(); } }
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/15132647.html
分类:
.Net-WinForm
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下