GDI 绘制圆角矩形
生活随笔
收集整理的這篇文章主要介紹了
GDI 绘制圆角矩形
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼從網上搜集
#region 圓角矩形/// /// 最大圓角半徑/// protected const int MaxRoundRadius = 3;/// /// 最小矩形邊長,用于自動處理圓角大小/// protected const int MinBorderLength = 20;/// /// 繪制一個圓角矩形./// /// 當前屏幕的圖形對象/// 矩形線條的顏色/// 矩形左上角X坐標/// 矩形左上角Y坐標/// 矩形右下角X坐標/// 矩形右下角Y坐標/// 圓角的半徑長度public static void DrawRoundRect(System.Drawing.Graphics currentGraphicObject, Color lineColor, int nLeft, int nTop, int nRight, int nBottom, int round){if (round > MaxRoundRadius){round = MaxRoundRadius;}else if (round < 0){round = 0;}if (Math.Abs(nRight - nLeft) < MinBorderLength && Math.Abs(nBottom - nTop) < MinBorderLength){round = 1;}Point Polygon1 = new Point(nLeft + round, nTop);Point Polygon2 = new Point(nRight - round + 1, nTop);Point Polygon3 = new Point(nLeft, nTop + round);Point Polygon4 = new Point(nRight + 1, nTop + round);Point Polygon5 = new Point(nLeft, nBottom - round);Point Polygon6 = new Point(nRight + 1, nBottom - round);Point Polygon7 = new Point(nLeft + round, nBottom + 1);Point Polygon8 = new Point(nRight - round, nBottom + 1);//四條主線(上下左右)currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon1.X, Polygon1.Y, Polygon2.X, Polygon2.Y);currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon7.X, Polygon7.Y, Polygon8.X, Polygon8.Y);currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon3.X, Polygon3.Y, Polygon5.X, Polygon5.Y);currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon4.X, Polygon4.Y, Polygon6.X, Polygon6.Y);//四個邊角currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon1.X, Polygon1.Y, Polygon3.X, Polygon3.Y);currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon2.X, Polygon2.Y, Polygon4.X, Polygon4.Y);currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon5.X, Polygon5.Y, Polygon7.X, Polygon7.Y);currentGraphicObject.DrawLine(new System.Drawing.Pen(lineColor), Polygon6.X, Polygon6.Y, Polygon8.X, Polygon8.Y);}/// /// 繪制一個圓角矩形./// /// 當前屏幕的圖形對象/// 矩形線條的顏色/// 要繪制的矩形對象/// 圓角的半徑長度public static void DrawRoundRect(System.Drawing.Graphics currentGraphicObject, Color lineColor, Rectangle rect, int round){DrawRoundRect(currentGraphicObject, lineColor, rect.Left, rect.Top, rect.Right, rect.Bottom, round);}/// /// 繪制一個圓角矩形./// /// 當前屏幕的圖形對象/// 矩形線條的顏色/// 要繪制的矩形對象public static void DrawRoundRect(System.Drawing.Graphics currentGraphicObject, Color lineColor, Rectangle rect){DrawRoundRect(currentGraphicObject, lineColor, rect.Left, rect.Top, rect.Right, rect.Bottom, 2);}/// /// 填充一個圓角矩形./// /// 當前屏幕的圖形對象/// 矩形線條的顏色/// 矩形左上角X坐標/// 矩形左上角Y坐標/// 矩形右下角X坐標/// 矩形右下角Y坐標/// 圓角的半徑長度public static void FillRoundRect(System.Drawing.Graphics currentGraphicObject, Color fillColor, int nLeft, int nTop, int nRight, int nBottom, int round){if (round > MaxRoundRadius){round = MaxRoundRadius;}else if (round < 0){round = 0;}if (Math.Abs(nRight - nLeft) < MinBorderLength && Math.Abs(nBottom - nTop) < MinBorderLength){round = 1;}Point Polygon1 = new Point(nLeft + round, nTop);Point Polygon2 = new Point(nRight - round + 1, nTop);Point Polygon3 = new Point(nLeft, nTop + round);Point Polygon4 = new Point(nRight + 1, nTop + round);Point Polygon5 = new Point(nLeft, nBottom - round);Point Polygon6 = new Point(nRight + 1, nBottom - round);Point Polygon7 = new Point(nLeft + round, nBottom + 1);Point Polygon8 = new Point(nRight - round, nBottom + 1);currentGraphicObject.FillPolygon(new System.Drawing.SolidBrush(fillColor), new Point[]{ Polygon1,Polygon3,Polygon5,Polygon7,Polygon8,Polygon6,Polygon4,Polygon2});}/// /// 填充一個圓角矩形./// /// 當前屏幕的圖形對象/// 矩形線條的顏色/// 要填充的矩形/// 填充區域針對矩形的縮進距離/// 圓角的半徑長度public static void FillRoundRect(System.Drawing.Graphics currentGraphicObject, Color lineColor, Rectangle rect, int indentSize, int round){FillRoundRect(currentGraphicObject, lineColor, rect.Left + indentSize, rect.Top + indentSize, rect.Right - indentSize + 1, rect.Bottom - indentSize + 1, round);}/// /// 填充一個圓角矩形./// /// 當前屏幕的圖形對象/// 矩形線條的顏色/// 要填充的矩形public static void FillRoundRect(System.Drawing.Graphics currentGraphicObject, Color lineColor, Rectangle rect){FillRoundRect(currentGraphicObject, lineColor, rect, 0, 2);}public static void FillRoundTitle(System.Drawing.Graphics currentGraphicObject, Color fillColor, int nLeft, int nTop, int nRight, int nBottom, int round,int Height){if (round > MaxRoundRadius){round = MaxRoundRadius;}else if (round < 0){round = 0;}if (Math.Abs(nRight - nLeft) < MinBorderLength && Math.Abs(nBottom - nTop) < MinBorderLength){round = 1;}Point Polygon1 = new Point(nLeft + round, nTop);Point Polygon2 = new Point(nRight - round + 1, nTop);Point Polygon3 = new Point(nLeft, nTop + round);Point Polygon4 = new Point(nRight + 1, nTop + round);Point Polygon5 = new Point(nLeft, nTop + Height);Point Polygon6 = new Point(nRight + 1, nTop + Height);currentGraphicObject.FillPolygon(new System.Drawing.SolidBrush(fillColor), new Point[]{ Polygon1,Polygon3,Polygon5,Polygon6,Polygon4,Polygon2});}public static void FillRoundTitle(System.Drawing.Graphics currentGraphicObject, Color lineColor, Rectangle rect, int indentSize, int round, int Height){FillRoundTitle(currentGraphicObject, lineColor, rect.Left + indentSize, rect.Top + indentSize, rect.Right - indentSize + 1, rect.Bottom - indentSize + 1, round, Height);}#endregion?
轉載于:https://www.cnblogs.com/zhangjianli/archive/2012/06/01/2530921.html
總結
以上是生活随笔為你收集整理的GDI 绘制圆角矩形的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 下载:Visual Studio 201
- 下一篇: ubuntu软件位置(安装位置, 运行文