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也可以根据自己的需要调整到最佳效
目录
打赏
0
0
0
0
16
分享
相关文章
WPF技术之图形系列Ellipse控件
WPF Ellipse是Windows Presentation Foundation (WPF)中的一个图形控件,它用于绘制椭圆形状。在WPF中,Ellipse可以用于创建具有椭圆形状的可视化效果,可以设置其位置、大小、填充颜色等属性。
1371 0
WPF技术之图形系列Rectangle控件
WPF Rectangle是Windows Presentation Foundation (WPF)中的一个图形控件,用于在界面上绘制矩形。它是一个非常常见的UI元素,可用于显示、布局和交互。
1340 0
C#-利用自定义控件绘制一个箭头控件
利用自定义控件绘制一个箭头控件
760 0
WPF 创建无边框的圆角窗口
原文:WPF 创建无边框的圆角窗口 如题所述,在WPF中要创建一个没有边框且为圆角的窗体,有如下几步工作要进行: 第一步:去掉窗体默认样式的边框 首先将窗体的背景设为透明,将允许透明的属性设置为True,...
2743 0
WPF 控件自定义背景
<!--控件要设置尺寸的话,设置的尺寸必须比下面的图形的尺寸要小,不然显示不开--> <Label Content="直角测试" Width="90" Height="90" HorizontalContentAlignment="Center" Vert...
1031 0
WPF中制作无边框窗体
原文:WPF中制作无边框窗体 众所周知,在WinForm中,如果要制作一个无边框窗体,可以将窗体的FormBorderStyle属性设置为None来完成。
1570 0
wpf无边框窗体移动和大小调整
原文:wpf无边框窗体移动和大小调整   using System; using System.Windows; using System.
1668 0
WPF 画线动画效果实现
原文:WPF 画线动画效果实现 弄了将近三天才搞定的,真是艰辛的实现。 看了很多博客,都太高深了,而且想要实现的功能都太强大了,结果基础部分一直实现不了,郁闷啊~ 千辛万苦终于找到了一个Demo,打开一看,代码只有20几行,不行我非要记一笔。
1170 0
WPF无边框拖动、全屏、缩放
原文:WPF无边框拖动、全屏、缩放 版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/lwwl12/article/details/78059361 先看效果 无边框 设置WindowStyle=”None”,窗口无关闭及缩放按钮,但还有黑边;设置AllowsTransparency=”True”,黑边没有了。
2156 0
WPF去除窗体边框及白色边框
原文:WPF去除窗体边框及白色边框        0
1504 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等