C# 圆角控件设计
来源:互联网 发布:qq同步mac电脑版 编辑:程序博客网 时间:2024/06/07 09:46
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也可以根据自己的需要调整到最佳效
- C# 圆角控件设计
- C#实现运行期控件设计
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理 .
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- C#控件及常用设计整理
- c#自定义圆角控件panel
- Studying note of GCC-3.4.6 source (104)
- zt自己动手用工行U盾加密自己私有文件
- Jode Decompiler插件
- NI LabWindows CVI 中调用 DLL 的几种方法
- C语言迷题
- C# 圆角控件设计
- 选择
- CISCO一路同行--记我的安全CCIE历程
- Linux教程- Vi的进入与退出
- 使用存储过程导出数据脚本
- c#数组简单排序方法
- c#深拷贝与浅拷贝
- 一个弹窗效果
- 关于类似RichEdit控件的设计思想