Nasıl yapılır: Bir Windows Formunda Doldurulmuş Dikdörtgen Çizme

Bu örnek, forma doldurulmuş bir dikdörtgen çizer.

Örnek

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

Kod Derleniyor

Bu yöntemi olay işleyicisinde Load çağıramazsınız. Form yeniden boyutlandırılırsa veya başka bir form tarafından gizlenirse, çizilen içerik yeniden çizilmeyecektir. İçeriğinizin otomatik olarak yeniden boyanması için yöntemini geçersiz kılmanız OnPaint gerekir.

Güçlü Programlama

Ve Graphics gibi Brush sistem kaynaklarını kullanan nesneleri her zaman çağırmalısınızDispose.

Ayrıca bkz.