GraphicsPath.AddPath(GraphicsPath, Boolean) 方法

定义

将指定的 GraphicsPath 追加到此路径。

C#
public void AddPath (System.Drawing.Drawing2D.GraphicsPath addingPath, bool connect);

参数

addingPath
GraphicsPath

要添加的 GraphicsPath

connect
Boolean

一个布尔值,该值指定添加路径中的第一个图是否是此路径中最后一个图的一部分。 true 值指定添加路径中的第一个图是此路径中最后一个图的一部分(如果可能)。 false 值指定所添加路径中的第一个图与此路径中的最后一个图分开。

示例

下面的代码示例旨在与 Windows 窗体一起使用,它需要 PaintEventArgseOnPaint 事件对象。 该代码执行以下操作:

  • 创建两个路径,一个右侧向上三角形,另一个是向上三角形。

  • 将第二个路径添加到第一个路径。

  • 绘制屏幕的结果路径。

C#
private void AddPathExample(PaintEventArgs e)
{
             
    // Create the first pathright side up triangle.
    Point[] myArray =
             {
                 new Point(30,30),
                 new Point(60,60),
                 new Point(0,60),
                 new Point(30,30)
             };
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddLines(myArray);
             
    // Create the second pathinverted triangle.
    Point[] myArray2 =
             {
                 new Point(30,30),
                 new Point(0,0),
                 new Point(60,0),
                 new Point(30,30)
             };
    GraphicsPath myPath2 = new GraphicsPath();
    myPath2.AddLines(myArray2);
             
    // Add the second path to the first path.
    myPath.AddPath(myPath2,true);
             
    // Draw the combined path to the screen.
    Pen myPen = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);
}

适用于

产品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9