Export (0) Print
Expand All

GraphicsPathIterator.NextPathType Method

Gets the starting index and the ending index of the next group of data points that all have the same type.

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

public int NextPathType(
	out byte pathType,
	out int startIndex,
	out int endIndex
)

Parameters

pathType
Type: System.Byte

[out] Receives the point type shared by all points in the group. Possible types can be retrieved from the PathPointType enumeration.

startIndex
Type: System.Int32

[out] Receives the starting index of the group of points.

endIndex
Type: System.Int32

[out] Receives the ending index of the group of points.

Return Value

Type: System.Int32
This method returns the number of data points in the group. If there are no more groups in the path, this method returns 0.

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

  • Creates a GraphicsPath object.

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

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

  • Creates a GraphicsPathIterator and rewinds it.

  • In a for loop, iterates through the points using the NextPathType and NextPathType methods.

  • Uses the values returned from the iterative calls to list the subpath number, the number of points in it, and the type of the path points to the right side of the screen.

  • Displays the value for the total number of points to the screen.

Note that ListPathPoints is a helper function that separates most (not all) of the display code from the graphics path code.

public void NextPathTypeExample(PaintEventArgs e)
{

    // Create the GraphicsPath.
    GraphicsPath myPath = new GraphicsPath();

    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, and an ellipse.
    myPath.AddLines(myPoints);
    myPath.AddRectangle(myRect);
    myPath.AddEllipse(220, 220, 100, 100);

    // List all of the path points to the screen.
    ListPathPoints(e, myPath, null, 20, 1);

    // Create a GraphicsPathIterator.
    GraphicsPathIterator myPathIterator = new
        GraphicsPathIterator(myPath);

    // Rewind the Iterator.
    myPathIterator.Rewind();

    // Iterate the subpaths and types, and list the results to 

    // the screen. 
    int i, j = 20;
    int mySubPaths, subPathStartIndex, subPathEndIndex;
    Boolean IsClosed;
    byte subPathPointType;
    int pointTypeStartIndex,  pointTypeEndIndex, numPointsFound;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);
    j = 20;
    for(i = 0;i < 3; i++)
    {
        mySubPaths = myPathIterator.NextSubpath(
            out subPathStartIndex,
            out subPathEndIndex,
            out IsClosed);
        numPointsFound = myPathIterator.NextPathType(
            out subPathPointType,
            out pointTypeStartIndex,
            out pointTypeEndIndex);
        e.Graphics.DrawString(
            "SubPath: " + i +
            "  Points Found: " + numPointsFound.ToString() +
            "  Type of Points: " + subPathPointType.ToString(),
            myFont,
            myBrush,
            200,
            j);
        j+=20;
    }

    // List the total number of path points to the screen.
    ListPathPoints(e, myPath, myPathIterator, 200, 2);
}

//------------------------------------------------------- 
//This function is a helper function used by 
// NextPathTypeExample. 
//------------------------------------------------------- 
public void ListPathPoints(
    PaintEventArgs e,
    GraphicsPath myPath,
    GraphicsPathIterator myPathIterator,
    int xOffset,
    int listType)
{

    // 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 drawing the points to the screen. 
    int i;
    float j = 20;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);
    if (listType == 1) 
        // List all the path points to the screen.
    {

        // Draw the set of path points and types to the screen. 
        for(i=0; i<myPathPointCount; i++)
        {
            e.Graphics.DrawString(myPathPoints[i].X.ToString()+
                ", " + myPathPoints[i].Y.ToString() + ", " +
                myPathTypes[i].ToString(),
                myFont,
                myBrush,
                xOffset,
                j);
            j+=20;
        }
    }
    else if (listType == 2) 
        // Display the total number of path points.
    {

        // Draw the total number of points to the screen. 
        int myPathTotalPoints = myPathIterator.Count;
        e.Graphics.DrawString("Total Points = " +
            myPathTotalPoints.ToString(),
            myFont,
            myBrush,
            xOffset,
            100);
    }
    else
    {
        e.Graphics.DrawString("Wrong or no list type argument.",
            myFont, myBrush, xOffset, 200);
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft