TableLayoutPanel.OnCellPaint(TableLayoutCellPaintEventArgs) Methode

Definition

Empfängt einen Aufruf, wenn die Zelle aktualisiert werden soll.

protected:
 virtual void OnCellPaint(System::Windows::Forms::TableLayoutCellPaintEventArgs ^ e);
protected virtual void OnCellPaint (System.Windows.Forms.TableLayoutCellPaintEventArgs e);
abstract member OnCellPaint : System.Windows.Forms.TableLayoutCellPaintEventArgs -> unit
override this.OnCellPaint : System.Windows.Forms.TableLayoutCellPaintEventArgs -> unit
Protected Overridable Sub OnCellPaint (e As TableLayoutCellPaintEventArgs)

Parameter

e
TableLayoutCellPaintEventArgs

Ein TableLayoutCellPaintEventArgs, das Daten für das Ereignis bereitstellt.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie die OnCellPaint Methode außer Kraft setzen, um eine benutzerdefinierte Darstellung für eine Zelle zu erstellen.

public class DemoTableLayoutPanel : TableLayoutPanel
{
    protected override void OnCellPaint(TableLayoutCellPaintEventArgs e)
    {
        base.OnCellPaint(e);

        Control c = this.GetControlFromPosition(e.Column, e.Row);

        if ( c != null )
        {
            Graphics g = e.Graphics;

            g.DrawRectangle(
                Pens.Red, 
                e.CellBounds.Location.X+1,
                e.CellBounds.Location.Y + 1,
                e.CellBounds.Width - 2, e.CellBounds.Height - 2);

            g.FillRectangle(
                Brushes.Blue, 
                e.CellBounds.Location.X + 1, 
                e.CellBounds.Location.Y + 1, 
                e.CellBounds.Width - 2, 
                e.CellBounds.Height - 2);
        };
    }
}
Public Class DemoTableLayoutPanel
    Inherits TableLayoutPanel

    Protected Overrides Sub OnCellPaint( _
    ByVal e As System.Windows.Forms.TableLayoutCellPaintEventArgs)

        MyBase.OnCellPaint(e)

        Dim c As Control = Me.GetControlFromPosition(e.Column, e.Row)

        If c IsNot Nothing Then
            Dim g As Graphics = e.Graphics

            g.DrawRectangle( _
            Pens.Red, _
            e.CellBounds.Location.X + 1, _
            e.CellBounds.Location.Y + 1, _
            e.CellBounds.Width - 2, _
            e.CellBounds.Height - 2)

            g.FillRectangle( _
            Brushes.Blue, _
            e.CellBounds.Location.X + 1, _
            e.CellBounds.Location.Y + 1, _
            e.CellBounds.Width - 2, _
            e.CellBounds.Height - 2)
        End If

    End Sub

End Class

Gilt für