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);
}


本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/09/07/1561797.html,如需转载请自行联系原作者
相关文章
|
2月前
|
C#
C# WinForm发送Email邮件
C# WinForm发送Email邮件
C# WinForm发送Email邮件
|
2月前
|
SQL 数据库连接 应用服务中间件
C#WinForm基础编程(三)
C#WinForm基础编程
104 0
|
2月前
C#WinForm基础编程(二)
C#WinForm基础编程
75 0
|
2月前
|
C# 数据安全/隐私保护
C#WinForm基础编程(一)
C#WinForm基础编程
70 0
|
7月前
|
小程序 C#
C#WinForm实现Loading等待界面
上篇博客中解决了程序加载时屏幕闪烁的问题。 但是,加载的过程变得很缓慢。 这个给用户的体验也不是很好,我这里想加一个Loading的进度条。 项目启动的时候,加载进度条,界面UI加载完毕,进度条消失。
197 0
|
9月前
|
关系型数据库 MySQL C#
C# winform 一个窗体需要调用自定义用户控件的控件名称
给用户控件ucQRCode增加属性: //二维码图片 private PictureBox _pictureBoxFSHLQrCode; public PictureBox PictureBoxFSHLQrCode {   get { return _pictureBoxFSHLQrCode; }   set { this.pictureBoxFSHLQrCode = value; } } 在Form1窗体直接调用即可: ucQRCode uQRCode=new ucQRCode(); ucQRCode.PictureBoxFSHLQrCode.属性= 要复制或传给用户控件上的控件的值
47 0
|
2月前
|
JavaScript C#
C#winForm程序与html JS交互调用
C#winForm程序与html JS交互调用
|
2月前
|
C# 开发者
35.c#:winform窗口
35.c#:winform窗口
19 1
|
10月前
|
程序员 C# 索引
C#之二十 Win Form对话框
C#之二十 Win Form对话框
49 0
|
10月前
|
Java C# 索引
C#之 十九 使用WinForm控件
C#之 十九 使用WinForm控件
146 0