次の方法で共有


方法: 開いている図形を塗りつぶす

GraphicsPath オブジェクトを FillPath メソッドに渡すことで、パスを埋めることができます。 FillPathメソッドは、パスに現在設定されているフィルモード (交互またはワインディング) に従ってパスを塗りつぶします。 パスに開いている図形がある場合、パスはそれらの図形が閉じられたかのように塗りつぶされます。 GDI+ は、終点から始点までの直線を描画して図形を閉じます。

次の例では、1 つの開いている図形 (円弧) と 1 つの閉じた図形 (楕円) を持つパスを作成します。 FillPathメソッドは、既定のフィル モード (Alternate) に従ってパスを塗りつぶします。

次の図は、コード例の出力を示しています。 ( Alternateに従って) パスが塗りつぶされていることに注意してください。これは、開いている図形が終点から始点までの直線で閉じられたかのように表示されます。

FillPath メソッドの出力を示す図

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);
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)

コードのコンパイル

前の例は Windows フォームで使用できるように設計されており、PaintEventArgs イベント ハンドラーのパラメーターである ePaintが必要です。

こちらも参照ください