c# 控件重绘事件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/never_tears/article/details/86678094

引用的控件需要更改 没有提供属性修改的设置时,可以通过重绘事件来更改UI

如:tableLayout 没有border,可以通过重绘来画出边框。tableLayout 重绘事件:

// 事件注册
this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(this.tableLayoutPanel1_CellPaint);

// 事件
private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
    // 单元格重绘
    Pen pp = new Pen(Color.Black);
    e.Graphics.DrawRectangle(pp, e.CellBounds.X, e.CellBounds.Y, e.CellBounds.X + e.CellBounds.Width - 1, e.CellBounds.Y + e.CellBounds.Height - 1);
}

猜你喜欢

转载自blog.csdn.net/never_tears/article/details/86678094