次の方法で共有


GraphicsPath.Clone メソッド

対象のパスの同一コピーを作成します。

Public Overridable Function Clone() As Object Implements _   ICloneable.Clone
[C#]
public virtual object Clone();
[C++]
public: virtual Object* Clone();
[JScript]
public function Clone() : Object;

戻り値

このメソッドが作成し、オブジェクトとしてキャストされる GraphicsPath

実装

ICloneable.Clone

使用例

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

  • パスを作成します。
  • パスに複数の図形を追加します。
  • 画面にパスを描画します。
  • そのパスのコピーのクローンを作成します。
  • 画面に新しいパスを描画します。

[Visual Basic, C#] Clone メソッドの呼び出しは、 GraphicsPath オブジェクトとしてキャストする必要があります。

 
Public Sub CloneExample(e As PaintEventArgs)
' Set several markers in a path.
Dim myPath As New GraphicsPath()
myPath.AddEllipse(0, 0, 100, 200)
myPath.AddLine(New Point(100, 100), New Point(200, 100))
Dim rect As New Rectangle(200, 0, 100, 200)
myPath.AddRectangle(rect)
myPath.AddLine(New Point(250, 200), New Point(250, 300))
' Draw the path to the screen.
Dim myPen As New Pen(Color.Black, 2)
e.Graphics.DrawPath(myPen, myPath)
' Clone a copy of myPath.
Dim myPath2 As GraphicsPath = CType(myPath.Clone(), GraphicsPath)
' Draw the path to the screen.
Dim myPen2 As New Pen(Color.Red, 4)
e.Graphics.DrawPath(myPen2, myPath2)
End Sub
        
[C#] 
private void CloneExample(PaintEventArgs e)
{
// Set several markers in a path.
GraphicsPath myPath = new GraphicsPath();
myPath.AddEllipse(0, 0, 100, 200);
myPath.AddLine(new Point(100, 100), new Point(200, 100));
Rectangle rect = new Rectangle(200, 0, 100, 200);
myPath.AddRectangle(rect);
myPath.AddLine(new Point(250, 200), new Point(250, 300));
// Draw the path to the screen.
Pen myPen = new Pen(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
// Clone a copy of myPath.
GraphicsPath myPath2 = (GraphicsPath)myPath.Clone();
// Draw the path to the screen.
Pen myPen2 = new Pen(Color.Red, 4);
e.Graphics.DrawPath(myPen2, myPath2);
}
        

[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 ファミリ

参照

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