Nasıl yapılır: Bir Windows Formunda Doldurulmuş Dikdörtgen Çizme
Bu örnek, bir form üzerinde 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
Olay işleyicisinde bu yöntemi çağrılamaz Load . Form başka bir form tarafından yeniden boyutlandırılmışsa veya gizlendiyse çizilen içerik yeniden çizilmez. İçeriğinizi otomatik olarak yeniden çizmeyi sağlamak için yöntemini geçersiz kılmanız gerekir OnPaint .
Güçlü Programlama
DisposeVe nesneleri gibi sistem kaynaklarını kullanan tüm nesneleri her zaman çağırmanız gerekir BrushGraphics .