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();
}
增加名稱空間:using System.Drawing.Drawing2D;
新增方法如下:當然各角的點可根據需要確定.
在窗體的paint和resize事件中增加:Type(this,20,0.1);
引數20和0.1也可以根據自己的需要調整到最佳效
{
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();
}
增加名稱空間:using System.Drawing.Drawing2D;
新增方法如下:當然各角的點可根據需要確定.
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->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);
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->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也可以根據自己的需要調整到最佳效
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-557460/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- iOS 繪製圓角iOS
- Winform窗體圓角以及描邊完美解決方案ORM
- canvas 繪製圓角矩形Canvas
- SVG 繪製圓角矩形SVG
- 利用DOTNETBAR製作圓角窗體和圓角控制元件控制元件
- C# WinForm 父窗體 子窗體 傳值C#ORM
- 微信小程式 canvas圓角矩形的繪製微信小程式Canvas
- canvas繪製圓角矩形程式碼例項Canvas
- c# winform窗體相關屬性C#ORM
- 原來 Canvas 也能直接繪製圓角矩形了Canvas
- Canvas 繪製 3d 圓柱體Canvas3D
- CSS 繪製半圓CSS
- canvas 繪製圓形Canvas
- SVG <circle> 繪製圓形SVG
- canvas 繪製矩形缺角Canvas
- c# winform旋轉顯示繪畫C#ORM
- PS製作圓角圖片
- c#窗體form(winform)事件event呼叫事件的簡小示例C#ORM事件
- 使用java繪圖類Graphics繪製圓圈Java繪圖
- 使用canvas繪製圓弧動畫Canvas動畫
- SVG <ellipse> 繪製橢圓SVG
- canvas繪製不重合的圓Canvas
- CSS繪製橢圓程式碼CSS
- 用CSS製作的圓角層CSS
- c# winform窗體之開啟檔案對話方塊openfiledialogC#ORM
- css3 繪製畫圓、扇形CSSS3
- canvas繪製多個圓圈效果Canvas
- 如何用pscc 2018圓角外掛mac版製作倒圓角Mac
- 使用canvas繪製圓形進度條Canvas
- BitmapShader繪製圓形圖片
- css繪製圓形程式碼例項CSS
- svg繪製半圓程式碼例項SVG
- html5中canvas繪製圓形HTMLCanvas
- flutter: 視窗初始與繪製流程Flutter
- canvas繪製三角形Canvas
- 解決WinForm(C#)中MDI子窗體最大化跑偏的問題ORMC#
- C# winForm 視窗跳轉後關閉上一個視窗的方法C#ORM
- winform之在主窗體中不顯示子窗體的選單欄ORM