方法 : 開いている図形を塗りつぶす
更新 : 2007 年 11 月
GraphicsPath オブジェクトを FillPath メソッドに渡すことによってパスを塗りつぶすことができます。FillPath メソッドは、パスに対して現在設定されている塗りつぶしモード (alternate または winding) に基づいて、パスを塗りつぶします。パスの図形が開いている場合でも、パスはその図形が閉じているかのように塗りつぶされます。GDI+ は、終了点から開始点に直線を描画することによってその図形を閉じます。
使用例
開いている図形 (円弧) と閉じた図形 (楕円) 1 つずつから成るパスを作成する例を次に示します。FillPath メソッドは、既定の塗りつぶしモード Alternate に基づいてパスを塗りつぶします。
プログラム例による出力を次の図に示します。パスは、開いている図形が終了点と開始点を結ぶ直線によって閉じられているかのように、Alternate に基づいて塗りつぶされます。
Dim path As New GraphicsPath()
' Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120)
' Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100)
Dim pen As New Pen(Color.FromArgb(128, 0, 0, 255), 5)
Dim brush As New SolidBrush(Color.Red)
' The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path)
e.Graphics.DrawPath(pen, path)
GraphicsPath path = new GraphicsPath();
// Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120);
// Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100);
Pen pen = new Pen(Color.FromArgb(128, 0, 0, 255), 5);
SolidBrush brush = new SolidBrush(Color.Red);
// The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path);
e.Graphics.DrawPath(pen, path);
コードのコンパイル方法
前述の例は Windows フォームと一緒に使用することが想定されていて、Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。