【发布时间】:2025-11-24 19:55:02
【问题描述】:
我有一个扩展 TableLayoutPanel 的类,定义/构造如下:
public class MyTableLayout : TableLayoutPanel
{
public MyTableLayout()
{
this.ColumnCount = 5;
this.RowCount = 1;
this.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
}
}
当我的表格被绘制时,它的所有 5 列都有边框(正如人们所期望的那样,因为代码可以设置上面的 CellBorderStyle)。
有什么方法可以防止在第一列周围绘制边框?
我知道你可以添加 CellPaint 回调:
this.CellPaint += tableLayoutPanel_CellPaint;
在这个回调中你可以做一些事情,比如改变特定列的边框颜色:
private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
if (e.Column == 0 && e.Row == 0)
{
e.Graphics.DrawRectangle(new Pen(Color.Red), e.CellBounds);
}
}
但是你如何绘制“否”矩形呢?
我尝试将颜色设置为 Color.Empty 但这不起作用:
e.Graphics.DrawRectangle(new Pen(Color.Empty), e.CellBounds);
【问题讨论】:
标签: c# winforms tablelayoutpanel