本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddLine方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.GraphicsPath.AddLine方法的具体用法?C# System.Drawing.Drawing2D.GraphicsPath.AddLine怎么用?C# System.Drawing.Drawing2D.GraphicsPath.AddLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.GraphicsPath.AddLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawRoundRect
/// <summary>
/// 绘制圆角
/// </summary>
/// <param name="g"></param>
/// <param name="p"></param>
/// <param name="X"></param>
/// <param name="Y"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="radius"></param>
public static void DrawRoundRect(Graphics g, Pen p, Brush brush,float X, float Y, float width, float height, float radius)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);
gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));
gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);
gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);
gp.CloseFigure();
g.DrawPath(p, gp);
g.FillPath(brush, gp);
gp.Dispose();
}
示例2: WndProc
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case 0xf:
Graphics g = this.CreateGraphics();
g.FillRectangle(BorderBrush, this.ClientRectangle);
//Create the path for the arrow
System.Drawing.Drawing2D.GraphicsPath pth = new System.Drawing.Drawing2D.GraphicsPath();
PointF TopLeft = new PointF(this.Width - 13, (this.Height - 5) / 2);
PointF TopRight = new PointF(this.Width - 6, (this.Height - 5) / 2);
PointF Bottom = new PointF(this.Width - 9, (this.Height + 2) / 2);
pth.AddLine(TopLeft, TopRight);
pth.AddLine(TopRight, Bottom);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//Draw the arrow
g.FillPath(new SolidBrush(Color.White), pth);
break;
default:
break;
}
}
示例3: Round
// 圆角代码
public void Round(System.Drawing.Region region)
{
// -----------------------------------------------------------------------------------------------
// 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API)
System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
int x = 0;
int y = 0;
int thisWidth = this.Width;
int thisHeight = this.Height;
int angle = _Radius;
if (angle > 0)
{
System.Drawing.Graphics g = CreateGraphics();
oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
// -----------------------------------------------------------------------------------------------
else
{
oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
}
示例4: getDrawingPoints
/// <summary>
/// takes in a parsed path and returns a list of points that can be used to draw the path
/// </summary>
/// <returns>The drawing points.</returns>
/// <param name="segments">Segments.</param>
public Vector2[] getDrawingPoints( List<SvgPathSegment> segments, float flatness = 3 )
{
var path = new System.Drawing.Drawing2D.GraphicsPath();
for( var j = 0; j < segments.Count; j++ )
{
var segment = segments[j];
if( segment is SvgMoveToSegment )
{
path.StartFigure();
}
else if( segment is SvgCubicCurveSegment )
{
var cubicSegment = segment as SvgCubicCurveSegment;
path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( cubicSegment.firstCtrlPoint ), toDrawPoint( cubicSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
}
else if( segment is SvgClosePathSegment )
{
// important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
if( path.PointCount > 0 && !path.PathPoints[0].Equals( path.PathPoints[path.PathPoints.Length - 1] ) )
{
var i = path.PathTypes.Length - 1;
while( i >= 0 && path.PathTypes[i] > 0 )
i--;
if( i < 0 )
i = 0;
path.AddLine( path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[i] );
}
path.CloseFigure();
}
else if( segment is SvgLineSegment )
{
path.AddLine( toDrawPoint( segment.start ), toDrawPoint( segment.end ) );
}
else if( segment is SvgQuadraticCurveSegment )
{
var quadSegment = segment as SvgQuadraticCurveSegment;
path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( quadSegment.firstCtrlPoint ), toDrawPoint( quadSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
}
else
{
Debug.warn( "unknown type in getDrawingPoints" );
}
}
path.Flatten( new System.Drawing.Drawing2D.Matrix(), flatness );
return System.Array.ConvertAll( path.PathPoints, i => new Vector2( i.X, i.Y ) );
}
示例5: DrawFilledPath
private void DrawFilledPath(SeriesBase series, System.Drawing.Pen pen,System.Drawing.Brush brush)
{
var path = new System.Drawing.Drawing2D.GraphicsPath();
if (series is AreaSeries)
{
path.StartFigure();
AreaSeries areaSeries = series as AreaSeries;
var points = areaSeries.AreaPoints;
var pointCount = areaSeries.AreaPoints.Count;
for (int i = 0; i < pointCount - 1; i++)
{
System.Drawing.PointF startPoint = points[i].AsDrawingPointF();
System.Drawing.PointF endPoint = points[i + 1].AsDrawingPointF();
path.AddLine(startPoint, endPoint);
}
path.CloseAllFigures();
switch (RenderingMode)
{
case RenderingMode.GDIRendering:
GDIGraphics.FillPath(brush, path);
break;
case RenderingMode.Default:
break;
case RenderingMode.WritableBitmap:
WritableBitmapGraphics.FillPath(brush, path);
break;
default:
break;
}
}
}
示例6: DrawRoundRect
public static System.Drawing.Drawing2D.GraphicsPath DrawRoundRect(Rectangle r, int r1, int r2, int r3, int r4)
{
float x = r.X;
float y = r.Y;
float width = r.Width;
float height = r.Height;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y);
path.AddLine(x + r1, y, (x + width) - r2, y);
path.AddBezier((x + width) - r2, y, x + width, y, x + width, y + r2, x + width, y + r2);
path.AddLine((float)(x + width), (float)(y + r2), (float)(x + width), (float)((y + height) - r3));
path.AddBezier((float)(x + width), (float)((y + height) - r3), (float)(x + width), (float)(y + height), (float)((x + width) - r3), (float)(y + height), (float)((x + width) - r3), (float)(y + height));
path.AddLine((float)((x + width) - r3), (float)(y + height), (float)(x + r4), (float)(y + height));
path.AddBezier(x + r4, y + height, x, y + height, x, (y + height) - r4, x, (y + height) - r4);
path.AddLine(x, (y + height) - r4, x, y + r1);
return path;
}
示例7: DrawRoundRect
// Zeichnet das Rechteck mit abgerundeten Ecken der Termindetails
public void DrawRoundRect(Graphics g, Pen p, float x, float y, float width, float height, float radius)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line
gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner
gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line
gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line
gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner
gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line
gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner
gp.CloseFigure();
g.DrawPath(p, gp);
gp.Dispose();
}
示例8: CreateLine2DPath
/// <summary>
/// Creates a GraphicsPath object and adds a line to it.
/// </summary>
/// <param name="x1">The x-coordinate of the starting point of the line.</param>
/// <param name="y1">The y-coordinate of the starting point of the line.</param>
/// <param name="x2">The x-coordinate of the endpoint of the line.</param>
/// <param name="y2">The y-coordinate of the endpoint of the line.</param>
/// <returns>Returns a GraphicsPath object containing the line.</returns>
public static System.Drawing.Drawing2D.GraphicsPath CreateLine2DPath(float x1, float y1, float x2, float y2)
{
System.Drawing.Drawing2D.GraphicsPath linePath = new System.Drawing.Drawing2D.GraphicsPath();
linePath.AddLine(x1, y1, x2, y2);
return linePath;
}
示例9: CreateGraphicsPath
/*******************************/
/// <summary>
/// Creates a GraphicsPath from two Int Arrays with a specific number of points.
/// </summary>
/// <param name="xPoints">Int Array to set the X points of the GraphicsPath</param>
/// <param name="yPoints">Int Array to set the Y points of the GraphicsPath</param>
/// <param name="pointsNumber">Number of points to add to the GraphicsPath</param>
/// <returns>A new GraphicsPath</returns>
public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(int[] xPoints, int[] yPoints, int pointsNumber)
{
System.Drawing.Drawing2D.GraphicsPath tempGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
if (pointsNumber == 2)
tempGraphicsPath.AddLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
else
{
System.Drawing.Point[] tempPointArray = new System.Drawing.Point[pointsNumber];
for (int index = 0; index < pointsNumber; index++)
tempPointArray[index] = new System.Drawing.Point(xPoints[index], yPoints[index]);
tempGraphicsPath.AddPolygon(tempPointArray);
}
return tempGraphicsPath;
}
示例10: intersectPolygon
//private static bool rectIntersectWithPolygon(RectangleF rect, Path path)
//{
// System.Drawing.Drawing2D.GraphicsPath temp = new System.Drawing.Drawing2D.GraphicsPath();
// temp.Reset();
// List<PointF> points = default(List<PointF>);
// foreach(object i in path.content)
// {
// if(i is Node)
// {
// Node node = (Node)i;
// if(rect.Contains((float)node.lon, (float)node.lat))
// return true;
// points.Add(new PointF((float)node.lon, (float)node.lat));
// }
// }
// temp.AddPolygon(points.ToArray());
// Region myRegion = new Region();
// myRegion.MakeEmpty();
// myRegion.Union(temp);
// PointF tempPt = new PointF();
// tempPt.X = rect.X;
// tempPt.Y = rect.Y;
// if(pointInPolygon(tempPt, myRegion))
// return true;
// tempPt.X = rect.X + rect.Width;
// tempPt.Y = rect.Y;
// if(pointInPolygon(tempPt, myRegion))
// return true;
// tempPt.X = rect.X;
// tempPt.Y = rect.Y + rect.Height;
// if(pointInPolygon(tempPt, myRegion))
// return true;
// tempPt.X = rect.X + rect.Width;
// tempPt.Y = rect.Y + rect.Height;
// if(pointInPolygon(tempPt, myRegion))
// return true;
// return false;
//}
private static bool intersectPolygon(RectangleF rect, Path path)
{
System.Drawing.Drawing2D.GraphicsPath temp = new System.Drawing.Drawing2D.GraphicsPath();
temp.Reset();
// List<PointF> points = default(List<PointF>);
List<PointF> points = new List<PointF>();
foreach (object i in path.content)
{
if (i is Node)
{
Node node = (Node)i;
if (rect.Contains((float)node.lon, (float)node.lat))
return true;
points.Add(new PointF((float)node.lon, (float)node.lat));
}
}
if (points.Count >= 3)
{
temp.AddPolygon(points.ToArray());
}
else if (points.Count == 2)
{
temp.AddLine(points[0], points[1]);
}
Region myRegion = new Region();
myRegion.MakeEmpty();
myRegion.Union(temp);
PointF tempPt = new PointF();
tempPt.X = rect.X;
tempPt.Y = rect.Y;
if (pointInPolygon(tempPt, myRegion))
return true;
tempPt.X = rect.X + rect.Width;
tempPt.Y = rect.Y;
if (pointInPolygon(tempPt, myRegion))
return true;
tempPt.X = rect.X;
tempPt.Y = rect.Y + rect.Height;
if (pointInPolygon(tempPt, myRegion))
return true;
tempPt.X = rect.X + rect.Width;
tempPt.Y = rect.Y + rect.Height;
if (pointInPolygon(tempPt, myRegion))
return true;
return false;
}
示例11: GetPath
private System.Drawing.Drawing2D.GraphicsPath GetPath(int index)
{
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.Reset();
Rectangle rect = this.GetTabRect(index);
if (index == 0)
{
path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + rect.Height, rect.Top + 2);
path.AddLine(rect.Left + rect.Height + 4, rect.Top, rect.Right - 3, rect.Top);
path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
}
else
{
if (index == this.SelectedIndex)
{
path.AddLine(rect.Left + 5 - rect.Height, rect.Bottom + 1, rect.Left + 4, rect.Top + 2);
path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left + 5 - rect.Height, rect.Bottom + 1);
}
else
{
path.AddLine(rect.Left, rect.Top + 6, rect.Left + 4, rect.Top + 2);
path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left, rect.Bottom + 1);
}
}
return path;
}
示例12: DrawFilled
/// <summary>
/// Draws a segment filled.
/// </summary>
public void DrawFilled(C2DSegment Segment, Graphics graphics, Brush brush)
{
C2DRect Rect = new C2DRect();
int nStartAngle = 0;
int nSweepAngle = 0;
GetArcParameters(Segment.Arc, Rect, ref nStartAngle, ref nSweepAngle);
if (nSweepAngle == 0)
nSweepAngle = 1;
int Width = (int)Rect.Width();
if (Width == 0)
Width = 1;
int Height = (int)Rect.Height();
if (Height == 0)
Height = 1;
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
Width, Height, nStartAngle, nSweepAngle);
C2DPoint ptFrom = Segment.Arc.Line.GetPointFrom();
C2DPoint ptTo = Segment.Arc.Line.GetPointTo();
ScaleAndOffSet(ptFrom);
ScaleAndOffSet(ptTo);
gp.AddLine((int)ptTo.x, (int)ptTo.y, (int)ptFrom.x, (int)ptFrom.y);
graphics.FillPath(brush, gp);
}
示例13: WndProc
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
/*if (m.Msg == WM_PAINT)
{
Graphics g = Graphics.FromHwnd(Handle);
Rectangle bounds = new Rectangle(0, 0, Width, Height);
ControlPaint.DrawBorder(g, bounds, _borderColor, _borderStyle);
}*/
switch (m.Msg)
{
case 0xf:
//Paint the background. Only the borders
//will show up because the edit
//box will be overlayed
//Graphics g = Graphics.FromHwnd(Handle);
Graphics g = this.CreateGraphics();
Rectangle bounds = new Rectangle(0, 0, Width, Height);
ControlPaint.DrawBorder(g, bounds, _borderColor, _borderStyle);
//Pen p = new Pen(Color.White, 2);
//g.FillRectangle(BorderBrush, this.ClientRectangle);
//Draw the background of the dropdown button
Rectangle rect = new Rectangle(this.Width - 18, 0, 18, this.Height);
g.FillRectangle(DropButtonBrush, rect);
//Create the path for the arrow
System.Drawing.Drawing2D.GraphicsPath pth = new System.Drawing.Drawing2D.GraphicsPath();
PointF TopLeft = new PointF(this.Width - 13, (this.Height - 5) / 2);
PointF TopRight = new PointF(this.Width - 6, (this.Height - 5) / 2);
PointF Bottom = new PointF(this.Width - 9, (this.Height + 2) / 2);
pth.AddLine(TopLeft, TopRight);
pth.AddLine(TopRight, Bottom);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//Determine the arrow's color.
if (this.DroppedDown)
{
ArrowBrush = new SolidBrush(SystemColors.HighlightText);
}
else
{
ArrowBrush = new SolidBrush(SystemColors.ControlText);
}
//Draw the arrow
g.FillPath(ArrowBrush, pth);
g.Dispose();
break;
}
}
示例14: ResolveGraphicsPath
static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path)
{
//convert from graphics path to internal presentation
System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath;
if (innerPath != null)
{
return innerPath;
}
//--------
innerPath = new System.Drawing.Drawing2D.GraphicsPath();
path.InnerPath = innerPath;
List<float> points;
List<PathCommand> cmds;
GraphicsPath.GetPathData(path, out points, out cmds);
int j = cmds.Count;
int p_index = 0;
for (int i = 0; i < j; ++i)
{
PathCommand cmd = cmds[i];
switch (cmd)
{
default:
throw new NotSupportedException();
case PathCommand.Arc:
innerPath.AddArc(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3],
points[p_index + 4],
points[p_index + 5]);
p_index += 6;
break;
case PathCommand.Bezier:
innerPath.AddBezier(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3],
points[p_index + 4],
points[p_index + 5],
points[p_index + 6],
points[p_index + 7]);
p_index += 8;
break;
case PathCommand.CloseFigure:
innerPath.CloseFigure();
break;
case PathCommand.Ellipse:
innerPath.AddEllipse(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]);
p_index += 4;
break;
case PathCommand.Line:
innerPath.AddLine(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]);
p_index += 4;
break;
case PathCommand.Rect:
innerPath.AddRectangle(
new System.Drawing.RectangleF(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]));
p_index += 4;
break;
case PathCommand.StartFigure:
break;
}
}
return innerPath;
}
示例15: ToGraphicsPath
/// <summary>
/// Converts this structure to a GraphicsPath object, used to draw to a Graphics device.
/// Consider that you can create a Region with a GraphicsPath object using one of the Region constructor.
/// </summary>
/// <returns></returns>
public System.Drawing.Drawing2D.GraphicsPath ToGraphicsPath()
{
if (mRectangle.IsEmpty)
return new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
if (mRoundValue == 0)
{
//Remove 1 from height and width to draw the border in the right location
//path.AddRectangle(new Rectangle(new Point(mRectangle.X - 1, mRectangle.Y - 1), mRectangle.Size));
path.AddRectangle(mRectangle);
}
else
{
int x = mRectangle.X;
int y = mRectangle.Y;
int lineShift = 0;
int lineShiftX2 = 0;
//Basically the RoundValue is a percentage of the line to curve, so I simply multiply it with the lower side (height or width)
if (mRectangle.Height < mRectangle.Width)
{
lineShift = (int)((double)mRectangle.Height * mRoundValue);
lineShiftX2 = lineShift * 2;
}
else
{
lineShift = (int)((double)mRectangle.Width * mRoundValue);
lineShiftX2 = lineShift * 2;
}
//Top
path.AddLine(lineShift + x, 0 + y, (mRectangle.Width - lineShift) + x, 0 + y);
//Angle Top Right
path.AddArc((mRectangle.Width - lineShiftX2) + x, 0 + y,
lineShiftX2, lineShiftX2,
270, 90);
//Right
path.AddLine(mRectangle.Width + x, lineShift + y, mRectangle.Width + x, (mRectangle.Height - lineShift) + y);
//Angle Bottom Right
path.AddArc((mRectangle.Width - lineShiftX2) + x, (mRectangle.Height - lineShiftX2) + y,
lineShiftX2, lineShiftX2,
0, 90);
//Bottom
path.AddLine((mRectangle.Width - lineShift) + x, mRectangle.Height + y, lineShift + x, mRectangle.Height + y);
//Angle Bottom Left
path.AddArc(0 + x, (mRectangle.Height - lineShiftX2) + y,
lineShiftX2, lineShiftX2,
90, 90);
//Left
path.AddLine(0 + x, (mRectangle.Height - lineShift) + y, 0 + x, lineShift + y);
//Angle Top Left
path.AddArc(0 + x, 0 + y,
lineShiftX2, lineShiftX2,
180, 90);
}
return path;
}