Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

GraphicsPathIterator.NextSubpath Method (Int32, Int32, Boolean)

Moves the GraphicsPathIterator to the next subpath in the path. The start index and end index of the next subpath are contained in the [out] parameters.

Namespace:  System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)
public int NextSubpath(
	out int startIndex,
	out int endIndex,
	out bool isClosed
)

Parameters

startIndex
Type: System.Int32

[out] Receives the starting index of the next subpath.

endIndex
Type: System.Int32

[out] Receives the ending index of the next subpath.

isClosed
Type: System.Boolean

[out] Indicates whether the subpath is closed.

Return Value

Type: System.Int32
The number of subpaths in the GraphicsPath object.

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.

  • Draws the values for the array of points to the screen.

  • Creates a GraphicsPathIterator object.

  • Calls the NextSubpath method.

  • Uses the values returned from the iterative calls to NextSubpath to draw the start and stop values for each subpath to the screen.

  • Draws the value for the total number of subpaths to the screen.

private void NextSubpathExample(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, an ellipse, and 2 markers.
    myPath.AddLines(myPoints);
    myPath.AddRectangle(myRect);
    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 drawing the array of 

    // points to the screen. 
    int i;
    float j = 20;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);

    // 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,
            20,
            j);
        j+=20;
    }

    // Create a GraphicsPathIterator.
    GraphicsPathIterator myPathIterator = new
        GraphicsPathIterator(myPath);
    int myStartIndex;
    int myEndIndex;
    bool myIsClosed;

    // get the number of Subpaths. 
    int numSubpaths = myPathIterator.NextSubpath(myPath,
        out myIsClosed);
    numSubpaths -= 1;

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

    // List the Subpaths to the screen.
    j=20;
    for(i=0;i<numSubpaths;i++)
    {
        myPathIterator.NextSubpath(out myStartIndex,
            out myEndIndex,
            out myIsClosed);
        e.Graphics.DrawString("Subpath " + i.ToString() +
            ":  Start: " + myStartIndex.ToString()+
            "  End: " + myEndIndex.ToString() +
            "  IsClosed: " + myIsClosed.ToString(),
            myFont,
            myBrush,
            200,
            j);
        j += 20;
    }

    // Draw the total number of Subpaths to the screen.
    j += 20;
    e.Graphics.DrawString("Number Subpaths = " +
        numSubpaths.ToString(),
        myFont,
        myBrush,
        200,
        j);
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.