本文介绍了TableLayoutPanel 的行/列着色(vs2008,winform)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在 TableLayoutPanel 中为整行或整列添加特定颜色吗?如何 ?如果有请提供示例代码..
Can i add particular color for entire Row or Column in TableLayoutPanel ?How ? please provide sample code if any ..
感谢广告.
推荐答案
是的,你可以.
使用 TableLayoutPanel 的 CellPaint 事件来测试哪个行/列调用了该事件,然后使用图形对象大小到矩形来设置单元格的颜色.
Use the TableLayoutPanel's CellPaint event to test for which row/column has called the event and then use a Graphic object size to the rectangle to set the cell's color.
像这样(第一行和第三行):
Like this (for the first and third rows):
private void Form_Load(object sender, EventArgs e) {
this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint);
}
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
if (e.Row == 0 || e.Row == 2) {
Graphics g = e.Graphics;
Rectangle r = e.CellBounds;
g.FillRectangle(Brushes.Blue, r);
}
}
这篇关于TableLayoutPanel 的行/列着色(vs2008,winform)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!