Export (0) Print
Expand All

GraphicsPath.Reset Method

Empties the PathPoints and PathTypes arrays and sets the FillMode to Alternate.

[Visual Basic]
Public Sub Reset()
[C#]
public void Reset();
[C++]
public: void Reset();
[JScript]
public function Reset();

Example

[Visual Basic, C#] 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 path.
  • Adds several primitives to it.
  • Draws the path's points array to the screen.
  • Resets the path to an empty state.
  • Re-acquires the points array (if it exists).
  • Draws the array to the screen.

[Visual Basic, C#] Notice that it finds no array following the reset call.

[Visual Basic] 
Public Sub GraphicsPathResetExample(e As PaintEventArgs)
Dim myFont As New Font("Arial", 8)
' Create a path and add a line, an ellipse, and an arc.
Dim myPath As New GraphicsPath()
myPath.AddLine(New Point(0, 0), New Point(100, 100))
myPath.AddEllipse(100, 100, 200, 250)
myPath.AddArc(300, 250, 100, 100, 0, 90)
' Draw the pre-reset points array to the screen.
DrawPointsHelper(e, myPath.PathPoints, 20)
' Reset the path.
myPath.Reset()
' See if any points remain.
If myPath.PointCount > 0 Then
' Draw the post-reset points array to the screen.
DrawPointsHelper(e, myPath.PathPoints, 150)
' If there are no points, say so.
Else
e.Graphics.DrawString("No Points", myFont, Brushes.Black, _
150, 20)
End If
End Sub
' A helper function used by GraphicsPathResetExample to draw points.
Public Sub DrawPointsHelper(e As PaintEventArgs, _
pathPoints() As PointF, xOffset As Integer)
Dim y As Integer = 20
Dim myFont As New Font("Arial", 8)
Dim i As Integer
For i = 0 To pathPoints.Length - 1
e.Graphics.DrawString(pathPoints(i).X.ToString() + _
", " + pathPoints(i).Y.ToString(), myFont, Brushes.Black, _
xOffset, y)
y += 20
Next i
End Sub
        
[C#] 
public void GraphicsPathResetExample(PaintEventArgs e)
{
Font myFont = new Font("Arial", 8);
// Create a path and add a line, an ellipse, and an arc.
GraphicsPath myPath = new GraphicsPath();
myPath.AddLine(new Point(0, 0), new Point(100, 100));
myPath.AddEllipse(100, 100, 200, 250);
myPath.AddArc(300, 250, 100, 100, 0, 90);
// Draw the pre-reset points array to the screen.
DrawPoints(e, myPath.PathPoints, 20);
// Reset the path.
myPath.Reset();
// See if any points remain.
if(myPath.PointCount > 0)
{
// Draw the post-reset points array to the screen.
DrawPoints(e, myPath.PathPoints, 150);
}
else
// If there are no points, say so.
e.Graphics.DrawString("No Points",
myFont,
Brushes.Black,
150,
20);
} //End GraphicsPathResetExample
// A helper function GraphicsPathResetExample uses to draw the points.
// to the screen.
public void DrawPoints(PaintEventArgs e, PointF[] pathPoints, int xOffset)
{
int y = 20;
Font myFont = new Font("Arial", 8);
for(int i=0;i < pathPoints.Length; i++)
{
e.Graphics.DrawString(pathPoints[i].X.ToString() + ", " +
pathPoints[i].Y.ToString(),
myFont,
Brushes.Black,
xOffset,
y);
y += 20;
}
} // End DrawPoints
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

GraphicsPath Class | GraphicsPath Members | System.Drawing.Drawing2D Namespace

Show:
© 2014 Microsoft