C# WinForm 绘制圆角窗体

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);
}
posted @   94cool  阅读(335)  评论(0编辑  收藏  举报
编辑推荐:
· 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代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
< 2009年9月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10
点击右上角即可分享
微信分享提示