次の方法で共有


GraphicsPathIterator.NextSubpath メソッド (GraphicsPath, Boolean)

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

Overloads Public Function NextSubpath( _
   ByVal path As GraphicsPath, _   <Out()> ByRef isClosed As Boolean _) As Integer
[C#]
public int NextSubpath(GraphicsPathpath,   out boolisClosed);
[C++]
public: int NextSubpath(GraphicsPath* path,   [   Out] bool* isClosed);
[JScript]
public function NextSubpath(
   path : GraphicsPath,isClosed : Boolean) : int;

パラメータ

  • path
    保持するデータ点が、反復子で取得した図形 (サブパス) のデータ点と一致するように設定されている GraphicsPath オブジェクト。
  • isClosed
    [出力] 現在のサブパスが閉じられているかどうかを示します。図形が閉じられている場合は true 、それ以外の場合は false です。

戻り値

取得した図形 (サブパス) 内のデータ点の数。それ以上図形がない場合は、0 を返します。

使用例

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

  • GraphicsPath オブジェクトを作成します。
  • 3 本の直線、1 つの四角形、1 つの楕円、および 1 組のマーカーを追加します。
  • すべてのパス内の点の値を画面の左側に一覧表示します。
  • GraphicsPathIterator オブジェクトを作成します。
  • 点のコピー先として、 GraphicsPath オブジェクト myPathSection を作成します。
  • NextSubpath(GraphicsPath) メソッドを呼び出します。このメソッドは、サブパスを反復処理して 3 番目のサブパス (図形) に移動し、そのサブパスに含まれているすべての点を myPathSection パスにコピーし、 subpathPoints にコピーされた点の数を返します。
  • サブパス番号と、その中に含まれている点の数を画面の右側に一覧表示します。
 
Public Sub NextSubpathExample2(e As PaintEventArgs)
' Create a graphics path.
Dim myPath As New GraphicsPath()
' Set up primitives to add to myPath.
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.SetMarkers()
myPath.AddRectangle(myRect)
myPath.SetMarkers()
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 for myPath.
Dim myPathIterator As New GraphicsPathIterator(myPath)
' Rewind the iterator.
myPathIterator.Rewind()
' Create the GraphicsPath section.
Dim myPathSection As New GraphicsPath()
' Draw the 3rd subpath and the number of points therein
' to the screen.
Dim subpathPoints As Integer
Dim IsClosed2 As Boolean
' Iterate to the third subpath.
subpathPoints = myPathIterator.NextSubpath(myPathSection, _
IsClosed2)
subpathPoints = myPathIterator.NextSubpath(myPathSection, _
IsClosed2)
subpathPoints = myPathIterator.NextSubpath(myPathSection, _
IsClosed2)
' Write the number of subpath points to the screen.
e.Graphics.DrawString("Subpath: 3" + "   Num Points: " + _
subpathPoints.ToString(), myFont, myBrush, 200, 20)
End Sub
        
[C#] 
public void NextSubpathExample2(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.AddLines(myPoints);
myPath.SetMarkers();
myPath.AddRectangle(myRect);
myPath.SetMarkers();
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 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 of all the 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 for myPath.
GraphicsPathIterator myPathIterator = new
GraphicsPathIterator(myPath);
// Rewind the iterator.
myPathIterator.Rewind();
// Create the GraphicsPath section.
GraphicsPath myPathSection = new GraphicsPath();
// Iterate to the 3rd subpath and list the number of points therein
// to the screen.
int subpathPoints;
bool IsClosed2;
// Iterate to the third subpath.
subpathPoints = myPathIterator.NextSubpath(
myPathSection, out IsClosed2);
subpathPoints = myPathIterator.NextSubpath(
myPathSection, out IsClosed2);
subpathPoints = myPathIterator.NextSubpath(
myPathSection, out IsClosed2);
// Write the number of subpath points to the screen.
e.Graphics.DrawString("Subpath: 3"  +
"   Num Points: " +
subpathPoints.ToString(),
myFont,
myBrush,
200,
20);
}
        

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

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

GraphicsPathIterator クラス | GraphicsPathIterator メンバ | System.Drawing.Drawing2D 名前空間 | GraphicsPathIterator.NextSubpath オーバーロードの一覧