次の方法で共有


方法 : Windows フォームに塗りつぶした四角形を描画する

この例は、塗りつぶした四角形をフォームに描画します。

使用例

Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.FillRectangle(myBrush, New Rectangle(0, 0, 200, 300))
myBrush.Dispose()
formGraphics.Dispose()
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(0, 0, 200, 300));
myBrush.Dispose();
formGraphics.Dispose();
System::Drawing::SolidBrush^ myBrush =
    gcnew System::Drawing::SolidBrush(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->FillRectangle(myBrush, Rectangle(0, 0, 200, 300));
delete myBrush;
delete formGraphics;

コードのコンパイル

Load イベント ハンドラーでこのメソッドを呼び出すことはできません。 フォームがサイズ変更された場合、または別のフォームによって隠れている場合、描画済みのコンテンツは再描画されません。 コンテンツを自動的に再描画するには、OnPaint メソッドをオーバーライドする必要があります。

信頼性の高いプログラミング

システム リソースを消費するオブジェクト (Brush オブジェクトや Graphics オブジェクトなど) では、必ず Dispose を呼び出す必要があります。

参照

参照

FillRectangle

OnPaint

概念

GDI+ でのブラシと塗りつぶされた図形

その他の技術情報

グラフィックス プログラミングについて

Windows フォームにおけるグラフィックスと描画

ペンを使用した直線と図形の描画