GraphicsPathIterator.NextMarker Method (GraphicsPath)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

This GraphicsPathIterator object has a GraphicsPath object associated with it. The NextMarker method increments the associated GraphicsPath to the next marker in its path and copies all the points contained between the current marker and the next marker (or end of path) to a second GraphicsPath object passed in to the parameter.

Namespace:   System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)

public int NextMarker(
	GraphicsPath path


Type: System.Drawing.Drawing2D.GraphicsPath

The GraphicsPath object to which the points will be copied.

Return Value

Type: System.Int32

The number of points between this marker and the next.

Use the SetMarkers method to set markers in a path. Markers are used to create groups of subpaths. One or more subpaths can be between two markers.

The following example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. The code performs the following actions:

  • Creates a GraphicsPath object.

  • Adds three lines, a rectangle, an ellipse, and two markers.

  • Lists the values of all the path's points to the left side of the screen.

  • Creates a GraphicsPathIterator object.

  • Creates a GraphicsPath object, myPathSection, to receive copied points.

  • Calls the NextMarker method, which iterates to the first marker and copies all the points contained between that marker and the next to myPathSection.

  • Returns the number of points copied to markerPoints.

  • Lists the marker number (the first marker) and number of points it contains to the right side of the screen.

public void NextMarkerExample2(PaintEventArgs e)

    // Create a graphics path.
    GraphicsPath myPath = new GraphicsPath();

    // Set up primitives to add to myPath.
    Point[] myPoints = {new Point(20, 20), new Point(120, 120), 
        new Point(20, 120),new Point(20, 20) };        

    Rectangle myRect = new Rectangle(120, 120, 100, 100);

    // Add 3 lines, a rectangle, an ellipse, and 2 markers.
    myPath.AddEllipse(220, 220, 100, 100);

    // Get the total number of points for the path,
    // and the arrays of the points and types.
    int myPathPointCount = myPath.PointCount;
    PointF[] myPathPoints = myPath.PathPoints;
    byte[] myPathTypes = myPath.PathTypes;

    // Set up variables for listing all the values of the path's
    // points to the screen.
    int i;
    float j = 20;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);

    // List the values for all of path points and types to
    // the left side of the screen.
    for(i=0; i < myPathPointCount; i++)
            ", " + myPathPoints[i].Y.ToString() + ", " +
            myPathTypes[i].ToString(),  myFont, myBrush,
            20, j);



    // Create a GraphicsPathIterator.
    GraphicsPathIterator myPathIterator = new

    // Rewind the iterator.

    // Create a GraphicsPath to receive a section of myPath.
    GraphicsPath myPathSection = new GraphicsPath();

    // Retrieve and list the number of points contained in

    // the first marker to the right side of the screen.
    int markerPoints;
    markerPoints = myPathIterator.NextMarker(myPathSection);
    e.Graphics.DrawString("Marker: 1" + "  Num Points: " +
        markerPoints.ToString(),  myFont, myBrush, 200, 20);


.NET Framework
Available since 1.1
Return to top