Auf Englisch lesen

Teilen über


PaintEventArgs Klasse

Definition

Stellt Daten für das Paint-Ereignis bereit.

C#
public class PaintEventArgs : EventArgs, IDisposable
C#
public class PaintEventArgs : EventArgs, IDisposable, System.Drawing.IDeviceContext
Vererbung
PaintEventArgs
Abgeleitet
Implementiert

Beispiele

Das folgende Beispiel veranschaulicht die Behandlung des Paint Ereignisses und die Verwendung der PaintEventArgs -Klasse zum Zeichnen von Rechtecken im Formular. Die MouseDown Ereignisse und MouseUp werden behandelt, um die Größe des Rechtecks zu bestimmen. Das Beispiel veranschaulicht auch die Invalidate Methode zum Ungültigmachen des Bereichs des Rechtecks, wodurch er neu gezeichnet wird.

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

Hinweise

Das Paint Ereignis tritt auf, wenn ein Steuerelement neu gezeichnet wird. Ein PaintEventArgs gibt den an, der Graphics zum Zeichnen des Steuerelements und zum ClipRectangle Zeichnen verwendet werden soll.

Informationen zum Ereignismodell finden Sie unter Behandeln und Auslösen von Ereignissen.

Konstruktoren

PaintEventArgs(Graphics, Rectangle)

Initialisiert eine neue Instanz der PaintEventArgs-Klasse mit der angegebenen Grafik und dem angegebenen Auswahlrechteck.

Eigenschaften

ClipRectangle

Ruft das Rechteck ab, in dem gezeichnet werden soll.

Graphics

Ruft die zum Zeichnen verwendete Grafik ab.

Methoden

Dispose()

Gibt alle vom PaintEventArgs verwendeten Ressourcen frei.

Dispose(Boolean)

Gibt die von PaintEventArgs verwendeten nicht verwalteten Ressourcen und optional die verwalteten Ressourcen frei.

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
Finalize()

Gibt einem Objekt Gelegenheit zu dem Versuch, Ressourcen freizugeben und andere Bereinigungen durchzuführen, bevor es von der Garbage Collection freigegeben wird.

GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Explizite Schnittstellenimplementierungen

IDeviceContext.GetHdc()

Gibt das Handle für einen Windows-Gerätekontext zurück.

IDeviceContext.ReleaseHdc()

Gibt das Handle eines Windows-Gerätekontexts frei.

Gilt für:

Produkt Versionen
.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

Weitere Informationen