c # 窗体圆角

简介: 引用:http://www.cnblogs.com/UouHt/archive/2009/02/23/1396544.html public void SetWindowRegion() {     System.

引用:http://www.cnblogs.com/UouHt/archive/2009/02/23/1396544.html

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也可以根据自己的需要调整到最佳效
相关文章
|
Java 数据库 C#
C#winforms实现windows窗体人脸识别
C#winforms实现windows窗体人脸识别
|
关系型数据库 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.属性= 要复制或传给用户控件上的控件的值
131 0
|
11月前
|
API C# Windows
【C#】在winform中如何实现嵌入第三方软件窗体
【C#】在winform中如何实现嵌入第三方软件窗体
585 0
|
开发框架 数据可视化 C#
C#中实现无标题栏窗体拖动的代码
C#中实现无标题栏窗体拖动的代码
|
C#
C#如何实现窗体最小化到托盘
C#如何实现窗体最小化到托盘
344 0
|
JavaScript Linux C#
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
306 0
|
C# 数据安全/隐私保护
ApeForms | C# WinForm窗体控件平滑减速运动
在桌面软件开发中,有时会需要控制窗体或控件移动以实现某些界面效果,比如幻灯片换页、侧面的展开栏等。 通常情况下我们会使用Timer以每隔一段时间修改一下坐标位置的方式来实现目标对象的位移效果,但通过这个方式实现的动效存在几个问题: 匀速运动效果生硬; 运动过程中不便灵活改变运动状态(如侧栏展开一半时令其收起); 动效多时需要创建多个Timer对象,不易管理且占用资源; ApeForms中为控件和窗体提供了平滑运动的扩展方法,很好的解决了这些问题。不仅是坐标的平滑运动,还有控件\窗体尺寸的平滑变化、透明度的平滑变化。允许在变化的中途随时更改目标坐标\尺寸\透明度,且使用共享的Timer
11532 1
ApeForms | C# WinForm窗体控件平滑减速运动
|
C# Windows
C#安装“Windows 窗体应用(.NET Framework)”
C#安装“Windows 窗体应用(.NET Framework)”
497 0
|
C# 数据安全/隐私保护
C# 窗体之间参数互相传递的两种方法与使用
C# 窗体之间参数互相传递的两种方法与使用
|
C# Kotlin
C#is、as关键字及获取当前活动窗体的实例
这篇日志记录一下C#中is关键字及as关键字的用法。 Is :判断检查对象是否与给定类型兼容 As :将对象转换为指定类型(强转),就跟(int )这样的用法是一样的。 获取当前窗体的活动子窗体。
130 0