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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Winform窗體圓角以及描邊完美解決方案ORM
- iOS 繪製圓角iOS
- canvas 繪製圓角矩形Canvas
- SVG 繪製圓角矩形SVG
- python繪製圓柱體Python
- 微信小程式 canvas圓角矩形的繪製微信小程式Canvas
- iOS開發_繪製圓角矩形虛線環iOS
- canvas 繪製立體圓環Canvas
- 原來 Canvas 也能直接繪製圓角矩形了Canvas
- Canvas 繪製 3d 圓柱體Canvas3D
- canvas 繪製圓形Canvas
- CSS 繪製半圓CSS
- CSS 繪製圓環CSS
- WinForm禁止窗體調整ORM
- SVG <ellipse> 繪製橢圓SVG
- SVG <circle> 繪製圓形SVG
- WinForm下實現子窗體ORM
- canvas 繪製矩形缺角Canvas
- PS製作圓角圖片
- 如何用pscc 2018圓角外掛mac版製作倒圓角Mac
- canvas繪製不重合的圓Canvas
- CSS繪製橢圓程式碼CSS
- Winform在主窗體載入前彈出登入窗體ORM
- C# winForm 視窗跳轉後關閉上一個視窗的方法C#ORM
- winform窗體常規設定記錄ORM
- 使用canvas繪製圓弧動畫Canvas動畫
- canvas繪製多個圓圈效果Canvas
- css3 繪製畫圓、扇形CSSS3
- flutter: 視窗初始與繪製流程Flutter
- winform之在主窗體中不顯示子窗體的選單欄ORM
- 解決winform窗體重複建立問題ORM
- css繪製圓形程式碼例項CSS
- 使用canvas繪製圓形進度條Canvas
- CSS繪製三角形CSS
- 如何用CAD繪製六角星
- C#窗體--滑鼠事件C#事件
- 前端學習筆記:使用canvas繪製有圓角的百分比進度條前端筆記Canvas
- 標準圓形餅圖Python繪製方法Python
- canvas繪製圓盤走動鐘錶效果Canvas