Nasıl yapılır: Anahatlı Şekil Çizme
Bu örnek, bir forma ana hatlı üç nokta ve dikdörtgen çizer.
Örnek
private:
void DrawEllipse()
{
System::Drawing::Pen^ myPen =
gcnew System::Drawing::Pen(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->DrawEllipse(myPen, Rectangle(0, 0, 200, 300));
delete myPen;
delete formGraphics;
}
private:
void DrawRectangle()
{
System::Drawing::Pen^ myPen =
gcnew System::Drawing::Pen(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->DrawRectangle(myPen, Rectangle(0, 0, 200, 300));
delete myPen;
delete formGraphics;
}
private void DrawEllipse()
{
System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.DrawEllipse(myPen, new Rectangle(0, 0, 200, 300));
myPen.Dispose();
formGraphics.Dispose();
}
private void DrawRectangle()
{
System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.DrawRectangle(myPen, new Rectangle(0, 0, 200, 300));
myPen.Dispose();
formGraphics.Dispose();
}
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0, 0, 200, 300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0, 0, 200, 300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
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
Oluşturduğunuz ve sistem kaynaklarını kullanan nesneleri her zaman çağırmalısınız Dispose . Önceki örnekte ve PenGraphics nesneleri oluşturuldu ve sonra atıldı.
Ayrıca bkz.
GitHub'da bizimle işbirliği yapın
Bu içeriğin kaynağı GitHub'da bulunabilir; burada ayrıca sorunları ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Daha fazla bilgi için katkıda bulunan kılavuzumuzu inceleyin.
.NET Desktop feedback
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin