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);
        };
}}这是微软的代码 我在form1里加了个 tableLayoutPanel有在 form1类后并上它 怎么它没有反映!!

解决方案 »

  1.   

    自定义控件,继承TableLayoutPanel
    生产DLL添加到form中
      

  2.   


            private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
            {           
                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);        }
    你+这个事件不完事了!!
      

  3.   

    protected override 就是要 重写