1 Star 0 Fork 122

库卡青年/DevelopAssistant

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
GraphicsPathHelper.cs 11.42 KB
一键复制 编辑 原始数据 按行查看 历史
wxd_tony1984 提交于 2016-04-11 22:24 +08:00 . 一些修改
/*
* 本代码受中华人民共和国著作权法保护,作者仅授权下载代码之人在学习和交流范围内
* 自由使用与修改代码;欲将代码用于商业用途的,请与作者联系。
* 使用本代码请保留此处信息。作者联系方式:ping3108@163.com, 欢迎进行技术交流
*/
using ICSharpCode.WinFormsUI.Controls;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace ICSharpCode.WinFormsUI.NGraphics
{
/// <summary>
/// 提供产生各种路径的静态方法,比如圆角路径、关闭按钮上的x路径、+号路径
/// </summary>
internal static class GraphicsPathHelper
{
/// <summary>
/// 画圆角矩形
/// </summary>
/// <param name="rect"></param>
/// <param name="cornerRadius"></param>
/// <returns></returns>
public static GraphicsPath CreateRoundedRectPath(Rectangle rect, int radius, RoundStyle type, bool shorten)
{
GraphicsPath roundedRect = new GraphicsPath();
roundedRect.AddArc(rect.X, rect.Y, radius * 2, radius * 2, 180, 90);
roundedRect.AddLine(rect.X + radius, rect.Y, rect.Right - radius * 2, rect.Y);
roundedRect.AddArc(rect.X + rect.Width - radius * 2, rect.Y, radius * 2, radius * 2, 270, 90);
roundedRect.AddLine(rect.Right, rect.Y + radius * 2, rect.Right, rect.Y + rect.Height - radius * 2);
roundedRect.AddArc(rect.X + rect.Width - radius * 2, rect.Y + rect.Height - radius * 2, radius * 2, radius * 2, 0, 90);
roundedRect.AddLine(rect.Right - radius * 2, rect.Bottom, rect.X + radius * 2, rect.Bottom);
roundedRect.AddArc(rect.X, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
roundedRect.AddLine(rect.X, rect.Bottom - radius * 2, rect.X, rect.Y + radius * 2);
roundedRect.CloseFigure();
return roundedRect;
}
public static GraphicsPath CreateRoundedRect(Rectangle rect, int radius, RoundStyle type, bool shorten)
{
GraphicsPath path = new GraphicsPath();
if (shorten)
{
rect.Width--;
rect.Height--;
}
Rectangle rectTopLeft = new Rectangle(rect.X, rect.Y, radius, radius);
Rectangle rectTopRight = new Rectangle(rect.Right - radius, rect.Y, radius, radius);
Rectangle rectBottomLeft = new Rectangle(rect.X, rect.Bottom - radius, radius, radius);
Rectangle rectBottomRight = new Rectangle(rect.Right - radius, rect.Bottom - radius, radius, radius);
Point p1 = new Point(rect.X, rect.Y);
Point p2 = new Point(rect.Right, rect.Y);
Point p3 = new Point(rect.Right, rect.Bottom);
Point p4 = new Point(rect.X, rect.Bottom);
switch (type)
{
case RoundStyle.None:
path.AddRectangle(rect);
break;
case RoundStyle.All:
path.AddArc(rectTopLeft, 180, 90);
path.AddArc(rectTopRight, 270, 90);
path.AddArc(rectBottomRight, 0, 90);
path.AddArc(rectBottomLeft, 90, 90);
break;
case RoundStyle.Top:
path.AddArc(rectTopLeft, 180, 90);
path.AddArc(rectTopRight, 270, 90);
path.AddLine(p3, p4);
break;
case RoundStyle.Bottom:
path.AddArc(rectBottomRight, 0, 90);
path.AddArc(rectBottomLeft, 90, 90);
path.AddLine(p1, p2);
break;
case RoundStyle.Left:
path.AddArc(rectBottomLeft, 90, 90);
path.AddArc(rectTopLeft, 180, 90);
path.AddLine(p2, p3);
break;
case RoundStyle.Right:
path.AddArc(rectTopRight, 270, 90);
path.AddArc(rectBottomRight, 0, 90);
path.AddLine(p4, p1);
break;
default:
break;
}
path.CloseFigure();
return path;
}
public static GraphicsPath CreateMinimizeFlagPath(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
int x = rect.X + (rect.Width - 9) / 2;
int y = rect.Y + (rect.Height - 7) / 2;
Point p1 = new Point(x + 1, y + 5);
Point p2 = new Point(x + 7, y + 5);
Point p3 = new Point(x + 1, y + 6);
Point p4 = new Point(x + 7, y + 6);
path.AddLines(new Point[] { p1, p2, p3, p4 });
return path;
}
public static GraphicsPath CreateMaximizeFlagPath(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
int x = rect.X + (rect.Width - 9) / 2;
int y = rect.Y + (rect.Height - 7) / 2;
Point p1 = new Point(x + 1, y + 1);
Point p2 = new Point(x + 7, y + 1);
path.AddRectangle(new Rectangle(new Point(x, y), new Size(8, 6)));
path.CloseFigure();
path.AddLine(p1, p2);
return path;
}
public static GraphicsPath CreateRestoreFlagPath(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
int x = rect.X + (rect.Width - 11) / 2;
int y = rect.Y + (rect.Height - 9) / 2;
Point p1 = new Point(x, y + 3);
Point p2 = new Point(x + 6, y + 3);
Point p3 = new Point(x + 6, y + 4);
Point p4 = new Point(x + 6, y + 8);
Point p5 = new Point(x, y + 8);
Point p6 = new Point(x, y + 4);
Point p7 = new Point(x + 7, y + 5);
Point p8 = new Point(x + 9, y + 5);
Point p9 = new Point(x + 9, y + 1);
Point p10 = new Point(x + 3, y + 1);
Point p11 = new Point(x + 3, y + 2);
Point p12 = new Point(x + 3, y);
Point p13 = new Point(x + 9, y);
path.AddLines(new Point[] { p1, p2, p4, p5, p6, p3, p2, p1 });
path.CloseFigure();
path.AddLines(new Point[] { p7, p8, p9, p10, p11, p12, p13, p8, p7 });
return path;
}
public static GraphicsPath CreateCloseFlagPath(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
int x = rect.X + (rect.Width - 9) / 2;
int y = rect.Y + (rect.Height - 7) / 2;
Point p1 = new Point(x + 1-1, y-1);
Point p2 = new Point(x + 7, y + 6);
Point p3 = new Point(x + 8, y + 6);
Point p4 = new Point(x + 2-1, y-1);
Point p5 = new Point(x + 6+1, y-1);
Point p6 = new Point(x, y + 6);
Point p7 = new Point(x + 1, y + 6);
Point p8 = new Point(x + 7+1, y-1);
path.AddLine(p1, p2);
path.AddLine(p3, p4);
path.CloseFigure();
path.AddLine(p5, p6);
path.AddLine(p7, p8);
return path;
}
public static GraphicsPath CreateTopRoundedPathForFormRegion(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
Point pBL = new Point(rect.X, rect.Bottom); // bottom left
Point pBR = new Point(rect.Right, rect.Bottom); // bottom right
int x = rect.X, y = rect.Y, r = rect.Right;
Point p1 = new Point(x, y + 4);
Point p2 = new Point(x + 1, y + 4);
Point p3 = new Point(x + 1, y + 2);
Point p4 = new Point(x + 2, y + 2);
Point p5 = new Point(x + 2, y + 1);
Point p6 = new Point(x + 4, y + 1);
Point p7 = new Point(x + 4, y);
Point p8 = new Point(r - 4, y);
Point p9 = new Point(r - 4, y + 1);
Point p10 = new Point(r - 2, y + 1);
Point p11 = new Point(r - 2, y + 2);
Point p12 = new Point(r - 1, y + 2);
Point p13 = new Point(r - 1, y + 4);
Point p14 = new Point(r, y + 4);
path.AddLines(new Point[] { p1, p2, p3, p4, p5, p6, p7 });
path.AddLines(new Point[] { p8, p9, p10, p11, p12, p13, p14 });
path.AddLine(pBR, pBL);
path.CloseFigure();
return path;
}
public static GraphicsPath CreateSingleLineCloseFlag(Rectangle rect, int width)
{
GraphicsPath path = new GraphicsPath();
int x = rect.X + (rect.Width - width) / 2;
int y = rect.Y + (rect.Height - width) / 2;
Point p1 = new Point(x, y);
Point p2 = new Point(x + width, y);
Point p3 = new Point(x + width, y + width);
Point p4 = new Point(x, y + width);
path.AddLine(p1, p3);
path.CloseFigure();
path.AddLine(p2, p4);
return path;
}
public static GraphicsPath CreateSingleLineCloseFlag(Rectangle rect)
{
return CreateSingleLineCloseFlag(rect, 6);
}
public static GraphicsPath CreatePlusFlag(Rectangle rect, int width)
{
GraphicsPath path = new GraphicsPath();
if (width % 2 == 1)
width++;
int x = rect.X + (rect.Width - width) / 2;
int y = rect.Y + (rect.Height - width) / 2;
Point p1 = new Point(x + width / 2 - 1, y);
Point p2 = new Point(x + width / 2 - 1, y + width - 1);
Point p3 = new Point(x + width / 2, y + width - 1);
Point p4 = new Point(x + width / 2, y);
Point p5 = new Point(x, y + width / 2 - 1);
Point p6 = new Point(x + width - 1, y + width / 2 - 1);
Point p7 = new Point(x + width - 1, y + width / 2);
Point p8 = new Point(x, y + width / 2);
path.AddLines(new Point[] { p1, p2, p3, p4 });
path.CloseFigure();
path.AddLines(new Point[] { p5, p6, p7, p8 });
return path;
}
public static GraphicsPath CreatePlusFlag(Rectangle rect)
{
return CreatePlusFlag(rect, 10);
}
public static GraphicsPath CreateDownTriangleFlag(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
int x = rect.X + (rect.Width - 10) / 2;
int y = rect.Y + (rect.Height - 9) / 2;
if (rect.Height % 2 == 0)
y++;
Point p1 = new Point(x, y);
Point p2 = new Point(x + 9, y);
Point p3 = new Point(x + 9, y + 1);
Point p4 = new Point(x, y + 1);
path.AddLines(new Point[] { p1, p2, p3, p4 });
path.CloseFigure();
int x1 = x, y1 = y + 4, x2 = x + 9, y2 = y + 4;
for (int i = 1; i <= 5; i++)
{
if (i % 2 == 0)
path.AddLine(x2, y2, x1, y1);
else
path.AddLine(x1, y1, x2, y2);
x1++;
x2--;
y1++;
y2++;
}
return path;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/wwwpythonpw/DevelopAssistant.git
git@gitee.com:wwwpythonpw/DevelopAssistant.git
wwwpythonpw
DevelopAssistant
DevelopAssistant
master

搜索帮助