다음을 통해 공유


TableLayoutPanel.OnCellPaint(TableLayoutCellPaintEventArgs) 메서드

정의

셀을 새로 고쳐야 할 때 호출을 받습니다.

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)

매개 변수

e
TableLayoutCellPaintEventArgs

이벤트에 대한 데이터를 제공하는 TableLayoutCellPaintEventArgs입니다.

예제

다음 코드 예제에서는 셀에 대 한 사용자 지정 모양을 만드는 메서드를 재정 OnCellPaint 의 하는 방법을 보여 줍니다.

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

적용 대상