TableLayoutCellPaintEventHandler 委托     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示用来处理 CellPaint 事件的方法。
public delegate void TableLayoutCellPaintEventHandler(System::Object ^ sender, TableLayoutCellPaintEventArgs ^ e);public delegate void TableLayoutCellPaintEventHandler(object sender, TableLayoutCellPaintEventArgs e);public delegate void TableLayoutCellPaintEventHandler(object? sender, TableLayoutCellPaintEventArgs e);type TableLayoutCellPaintEventHandler = delegate of obj * TableLayoutCellPaintEventArgs -> unitPublic Delegate Sub TableLayoutCellPaintEventHandler(sender As Object, e As TableLayoutCellPaintEventArgs)参数
- sender
- Object
事件源。
示例
以下示例演示如何 TableLayoutCellPaintEventHandler 委托自定义控件的外观 TableLayoutPanel 。 此代码示例是为 控件提供的更大示例的 TableLayoutPanel 一部分。
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
注解
创建 TableLayoutCellPaintEventHandler 委托时,需要确定处理事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件。
扩展方法
| GetMethodInfo(Delegate) | 获取指示指定委托表示的方法的对象。 |