次の方法で共有


GraphicsPathIterator.NextSubpath メソッド

指定された GraphicsPath オブジェクト内の現在のサブパスから次のサブパスに移動します。

オーバーロードの一覧

GraphicsPathIterator オブジェクトに関連付けられているパスから、次の図形 (サブパス) を取得します。

[Visual Basic] Overloads Public Function NextSubpath(GraphicsPath, ByRef Boolean) As Integer

[C#] public int NextSubpath(GraphicsPath, bool);

[C++] public: int NextSubpath(GraphicsPath*, bool);

[JScript] public function NextSubpath(GraphicsPath, Boolean) : int;

GraphicsPathIterator オブジェクトをパス内の次のサブパスに移動します。次のサブパスの開始インデックスおよび終了インデックスが、[out] パラメータに格納されます。

[Visual Basic] Overloads Public Function NextSubpath(ByRef Integer, ByRef Integer, ByRef Boolean) As Integer

[C#] public int NextSubpath(int, int, bool);

[C++] public: int NextSubpath(int, int, bool);

[JScript] public function NextSubpath(int, int, Boolean) : int;

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 OnPaint イベントのオブジェクトである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • GraphicsPath オブジェクトを作成します。
  • 3 本の直線、1 つの四角形、および 1 つの楕円を追加します。
  • 画面に点の配列の値を描画します。
  • GraphicsPathIterator オブジェクトを作成します。
  • NextSubpath メソッドを呼び出します。
  • NextSubPath の反復呼び出しによって返された値を使用して、各サブパスの開始値と終了値を画面に描画します。
  • 画面にサブパスの合計数を表す値を描画します。

[Visual Basic, C#] メモ   ここでは、NextSubpath のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Public Sub NextSubpathExample(e As PaintEventArgs)
' Create the GraphicsPath.
Dim myPath As New GraphicsPath()
Dim myPoints As Point() =  {New Point(20, 20), _
New Point(120, 120), New Point(20, 120), New Point(20, 20)}
Dim myRect As 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.
Dim myPathPointCount As Integer = myPath.PointCount
Dim myPathPoints As PointF() = myPath.PathPoints
Dim myPathTypes As Byte() = myPath.PathTypes
' Set up variables for drawing the array of points to the screen.
Dim i As Integer
Dim j As Single = 20
Dim myFont As New Font("Arial", 8)
Dim myBrush As New SolidBrush(Color.Black)
' Draw the set of path points and types to the screen.
For i = 0 To myPathPointCount - 1
e.Graphics.DrawString(myPathPoints(i).X.ToString() + ", " + _
myPathPoints(i).Y.ToString() + ", " + _
myPathTypes(i).ToString(), myFont, myBrush, 20, j)
j += 20
Next i
' Create a GraphicsPathIterator.
Dim myPathIterator As New GraphicsPathIterator(myPath)
Dim myStartIndex As Integer
Dim myEndIndex As Integer
Dim myIsClosed As Boolean
' get the number of Subpaths.
Dim numSubpaths As Integer = myPathIterator.NextSubpath(myPath, _
myIsClosed)
numSubpaths -= 1
' Rewind the Iterator.
myPathIterator.Rewind()
' List the Subpaths to the screen.
j = 20
For i = 0 To numSubpaths - 1
myPathIterator.NextSubpath(myStartIndex, myEndIndex, _
myIsClosed)
e.Graphics.DrawString("Subpath " + i.ToString() + _
":  Start: " + myStartIndex.ToString() + "  End: " + _
myEndIndex.ToString() + "  IsClosed: " + _
myIsClosed.ToString(), myFont, myBrush, 200, j)
j += 20
Next i
' Draw the total number of Subpaths to the screen.
j += 20
e.Graphics.DrawString("Number Subpaths = " + _
numSubpaths.ToString(), myFont, myBrush, 200, j)
End Sub
        
[C#] 
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);
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

GraphicsPathIterator クラス | GraphicsPathIterator メンバ | System.Drawing.Drawing2D 名前空間