İngilizce dilinde oku

Aracılığıyla paylaş


PaintEventArgs Sınıf

Tanım

Paint olayı için veriler sağlar.

C#
public class PaintEventArgs : EventArgs, IDisposable
C#
public class PaintEventArgs : EventArgs, IDisposable, System.Drawing.IDeviceContext
Devralma
PaintEventArgs
Türetilmiş
Uygulamalar

Örnekler

Aşağıdaki örnek, olayı işlemeyi Paint ve forma dikdörtgenler çizmek için sınıfını kullanmayı PaintEventArgs gösterir. MouseDown ve MouseUp olayları dikdörtgenin boyutunu belirlemek için işlenir. Örnekte ayrıca dikdörtgenin Invalidate alanını geçersiz kılma yönteminin de gösterilmesi, bunun yeniden çizilmesine neden olur.

C#

private Rectangle RcDraw;
private float PenWidth = 5;

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{

    // Determine the initial rectangle coordinates...

    RcDraw.X = e.X;
    RcDraw.Y = e.Y;
}

private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{

    // Determine the width and height of the rectangle...

    if(e.X < RcDraw.X)
    {
        RcDraw.Width = RcDraw.X - e.X;
        RcDraw.X = e.X;
    }
    else
    {
        RcDraw.Width = e.X - RcDraw.X;
    }

    if(e.Y < RcDraw.Y)
    {
        RcDraw.Height = RcDraw.Y - e.Y;
        RcDraw.Y = e.Y;
    }
    else
    {
        RcDraw.Height = e.Y - RcDraw.Y;
    }

    // Force a repaint of the region occupied by the rectangle...

    this.Invalidate(RcDraw);
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

    // Draw the rectangle...

    e.Graphics.DrawRectangle(new Pen(Color.Blue, PenWidth), RcDraw);
}
C#
// This example creates a PictureBox control on the form and draws to it.
// This example assumes that the Form_Load event handler method is
// connected to the Load event of the form.

private PictureBox pictureBox1 = new PictureBox();
// Cache font instead of recreating font objects each time we paint.
private Font fnt = new Font("Arial",10);
private void Form1_Load(object sender, System.EventArgs e)
{
    // Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill;
    pictureBox1.BackColor = Color.White;
    // Connect the Paint event of the PictureBox to the event handler method.
    pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);

    // Add the PictureBox control to the Form.
    this.Controls.Add(pictureBox1);
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    // Create a local version of the graphics object for the PictureBox.
    Graphics g = e.Graphics;

    // Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control",
        fnt, System.Drawing.Brushes.Blue, new Point(30,30));
    // Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, pictureBox1.Top,
        pictureBox1.Right, pictureBox1.Bottom);
}

Açıklamalar

Olay Paint , bir denetim yeniden çizildiğinde gerçekleşir. A PaintEventArgs , Graphics denetimi ve ClipRectangle boyanacak öğeyi boyamak için kullanılacak öğesini belirtir.

Olay modeli hakkında bilgi için bkz. Olayları İşleme ve Oluşturma.

Oluşturucular

PaintEventArgs(Graphics, Rectangle)

Belirtilen grafik ve kırpma dikdörtgeni ile sınıfının yeni bir örneğini PaintEventArgs başlatır.

Özellikler

ClipRectangle

Boyanacak dikdörtgeni alır.

Graphics

Boyamak için kullanılan grafikleri alır.

Yöntemler

Dispose()

PaintEventArgs tarafından kullanılan tüm kaynakları serbest bırakır.

Dispose(Boolean)

PaintEventArgs tarafından kullanılan yönetilmeyen kaynakları serbest bırakır ve yönetilen kaynakları isteğe bağlı olarak serbest bırakır.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
Finalize()

Bir nesnenin atık toplama tarafından geri kazanılmadan önce kaynakları boşaltmaya ve diğer temizleme işlemlerini gerçekleştirmeye çalışmasına izin verir.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Belirtik Arabirim Kullanımları

IDeviceContext.GetHdc()

Tanıtıcıyı bir Windows cihaz bağlamı için döndürür.

IDeviceContext.ReleaseHdc()

Windows cihaz bağlamının tutamacını serbest bırakır.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Ayrıca bkz.