98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using Color = System.Drawing.Color;
|
|
using Point = System.Drawing.Point;
|
|
using Rectangle = System.Drawing.Rectangle;
|
|
|
|
namespace ShrlAlgoToolkit.Core.Assists;
|
|
|
|
public static class GdiAssist
|
|
{
|
|
public static void DrawArc(Graphics graphics)
|
|
{
|
|
Pen myPen = new(Color.Blue, 5);
|
|
Rectangle myRectangle = new(70, 20, 100, 60);
|
|
graphics.DrawArc(myPen, myRectangle, 210, 120);
|
|
}
|
|
|
|
public static void DrawBezier(Graphics graphics)
|
|
{
|
|
Pen myPen = new(Color.Red, 5);
|
|
var startX = 50.0F;
|
|
var startY = 80.0F;
|
|
var controlX1 = 150.0F;
|
|
var controlY1 = 20.0F;
|
|
var controlX2 = 230.0F;
|
|
var controlY2 = 50.0F;
|
|
var endX = 190.0F;
|
|
var endY = 80.0F;
|
|
graphics.DrawBezier(myPen, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY);
|
|
}
|
|
|
|
public static void DrawCurve(Graphics graphics)
|
|
{
|
|
Pen myPen = new(Color.Red, 5);
|
|
Point point1 = new(50, 20);
|
|
Point point2 = new(60, 30);
|
|
Point point3 = new(70, 25);
|
|
Point point4 = new(100, 50);
|
|
Point point5 = new(130, 30);
|
|
Point point6 = new(150, 45);
|
|
Point[] myPoints = { point1, point2, point3, point4, point5, point6 };
|
|
graphics.DrawCurve(myPen, myPoints, 1.0F);
|
|
}
|
|
|
|
public static void DrawEllipse(Graphics graphics)
|
|
{
|
|
Pen myPen = new(Color.Blue, 3);
|
|
Rectangle myRectangle = new(70, 20, 100, 60);
|
|
graphics.DrawEllipse(myPen, myRectangle);
|
|
}
|
|
|
|
public static void DrawLine(Graphics graphics)
|
|
{
|
|
//Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
|
|
Pen myPen = new(Color.Blue, 2);
|
|
graphics.DrawLine(myPen, 50, 30, 170, 30);
|
|
}
|
|
|
|
public static void DrawLine(Graphics graphics, Point p1, Point p2)
|
|
{
|
|
//Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
|
|
Pen myPen = new(Color.Blue, 2);
|
|
graphics.DrawLine(myPen, p1.X, p1.Y, p2.X, p2.Y);
|
|
}
|
|
|
|
public static void DrawPath(Graphics graphics)
|
|
{
|
|
GraphicsPath myGraphicsPath = new();
|
|
Pen myPen = new(Color.Blue, 1);
|
|
Point[] myPoints = { new(15, 30), new(30, 40), new(50, 30) };
|
|
myGraphicsPath.AddArc(15, 20, 80, 50, 210, 120);
|
|
myGraphicsPath.StartFigure();
|
|
myGraphicsPath.AddCurve(myPoints);
|
|
myGraphicsPath.AddString("图形路径", new FontFamily("华文行楷"), (int)FontStyle.Underline, 50, new PointF(20, 50), new StringFormat());
|
|
myGraphicsPath.AddPie(180, 20, 80, 50, 210, 120);
|
|
graphics.DrawPath(myPen, myGraphicsPath);
|
|
}
|
|
|
|
public static void DrawPolygon(Graphics graphics)
|
|
{
|
|
Pen myPen = new(Color.Red, 5);
|
|
Point point1 = new(80, 20);
|
|
Point point2 = new(40, 50);
|
|
Point point3 = new(80, 80);
|
|
Point point4 = new(160, 80);
|
|
Point point5 = new(200, 50);
|
|
Point point6 = new(160, 20);
|
|
Point[] myPoints = { point1, point2, point3, point4, point5, point6 };
|
|
graphics.DrawPolygon(myPen, myPoints);
|
|
}
|
|
|
|
public static void DrawRectangle(Graphics graphics)
|
|
{
|
|
Pen myPen = new(Color.Blue, 2);
|
|
graphics.DrawRectangle(myPen, 70, 20, 80, 50);
|
|
}
|
|
}
|