C# WinForm 绘制圆角窗体

简介: public void SetWindowRegion() { System.Drawing.Drawing2D.GraphicsPath FormPath; FormPath = new System.
public void SetWindowRegion()
{
System.Drawing.Drawing2D.GraphicsPath FormPath;
FormPath = new System.Drawing.Drawing2D.GraphicsPath();
Rectangle rect = new Rectangle(0, 22, this.Width, this.Height - 22);//this.Left-10,this.Top-10,this.Width-10,this.Height-10);
    FormPath = GetRoundedRectPath(rect, 30);
this.Region = new Region(FormPath);
}
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
{
int diameter = radius;
Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
GraphicsPath path = new GraphicsPath();
//   左上角
    path.AddArc(arcRect, 180, 90);
//   右上角
    arcRect.X = rect.Right - diameter;
path.AddArc(arcRect, 270, 90);
//   右下角
    arcRect.Y = rect.Bottom - diameter;
path.AddArc(arcRect, 0, 90);
//   左下角
    arcRect.X = rect.Left;
path.AddArc(arcRect, 90, 90);
path.CloseFigure();
return path;
}
protected override void OnResize(System.EventArgs e)
{
this.Region = null;
SetWindowRegion();
}

教你一招:构造圆角窗体 
http://topic.csdn.net/t/20041128/19/3596094.html 

增加命名空间:using System.Drawing.Drawing2D; 
添加方法如下:当然各角的点可根据需要确定.
复制   保存
private void Type(Control sender, int p_1, double p_2)
{
GraphicsPath oPath = new GraphicsPath();
oPath.AddClosedCurve(
new Point[] {
new Point(0, sender.Height / p_1),
new Point(sender.Width / p_1, 0),
new Point(sender.Width - sender.Width / p_1, 0),
new Point(sender.Width, sender.Height / p_1),
new Point(sender.Width, sender.Height - sender.Height / p_1),
new Point(sender.Width - sender.Width / p_1, sender.Height),
new Point(sender.Width / p_1, sender.Height),
new Point(0, sender.Height - sender.Height / p_1) },
(float) p_2);
sender.Region = new Region(oPath);
}

在窗体的paint和resize事件中增加:Type(this,20,0.1); 
参数20和0.1也可以根据自己的需要调整到最佳效
目录
相关文章
如何将DataGridView中的滚动条显示出来
1、选项设置   DataGridView有一个ScrollBars,可以设置水平滚动条,垂直滚动条,或者两种包含。   2、实际运行效果
5900 0
|
存储 搜索推荐 前端开发
变革来袭!多Agent框架MuAgent带你解锁代码开发新姿势
在这个信息技术爆炸的时代,我们都知道大型语言模型(LLM)拥有处理复杂问题的能力,但当遇到编程难题这种更高级的挑战时,单独的LLM Agent可能就不够看了。社区里动起了脑筋,玩出了新花样——组合多个Agent来应对高难度挑战!正如Multi Agent的构建过程所示,与其说我们是在设计Agents,不如说是对当前需求的深入理解后去构建出一条专属于某个场景的SOP。
1609 2
ASCII编码字符分布
ASCII编码字符分布
941 2
|
自然语言处理 JavaScript 前端开发
vue2 div滚动条下拉到底部时触发事件(懒加载) 超级简易版本的懒加载
vue2 div滚动条下拉到底部时触发事件(懒加载) 超级简易版本的懒加载
710 2
|
C# 容器
WPF技术之Expander控件
WPF Expander控件是一个可折叠展开的容器,它允许用户在需要时展开或折叠其内容。它提供了一种在图形界面中组织和隐藏信息的方式。
860 0
|
前端开发 JavaScript Java
基于Springboot+SpringSecurity+Activiti7实现的工作流系统可方便二次开发(附完整源码)
基于Springboot+SpringSecurity+Activiti7实现的工作流系统可方便二次开发(附完整源码)
619 0
|
机器学习/深度学习 人工智能 算法
一文读懂目标检测AI算法:R-CNN,faster R-CNN,yolo,SSD,yoloV2
## 1 引言 深度学习目前已经应用到了各个领域,应用场景大体分为三类:物体识别,目标检测,自然语言处理。上文我们对物体识别领域的技术方案,也就是CNN进行了详细的分析,对LeNet-5 AlexNet VGG Inception ResNet MobileNet等各种优秀的模型框架有了深入理解。本文着重与分析目标检测领域的深度学习方法,对其中的经典模型框架进行深入分析。 目标检测可以
19567 0
|
NoSQL Ubuntu Linux
掌握QEMU虚拟化技术:搭建ARM64+Linux调试环境实战指南
掌握QEMU虚拟化技术:搭建ARM64+Linux调试环境实战指南
|
开发框架 JSON 资源调度
Locust压测框架入门
Locust压测框架入门
396 0
|
关系型数据库 MySQL 网络安全
阿里云服务器MySQL 8.0开启远程连接
云服务器MySQL 8.0开启远程连接
阿里云服务器MySQL 8.0开启远程连接