【发布时间】:2010-08-14 15:17:17
【问题描述】:
我有一个派生自 TableLayoutPanel 的类。此类构成表格更正(网格 3x8)并在某些单元格中添加一些复选框。所有这些都是通过重写函数 InitLayout() 来完成的。
public class TableLayoutPanelHours : TableLayoutPanel
{
protected override void InitLayout()
{
RowCount = 3;
ColumnCount = 8;
// Set some column and row styles
RowStyles[0].SizeType = SizeType.Percent;
RowStyles[0].Height = (100 / RowCount);
// ... etc ...
// ... create checkbox with the name checkbox1
Controls.Add(checkbox1, 1, 1); // Put in cell 1x1
// ... etc ...
}
}
构建完成后,可以从VS2010的工具箱中获取控件。
然后,将控件放在一个简单的 Windows 窗体上,会发生一些我不理解的事情: - 在设计模式下,控件尚未化妆。 TableLayoutPanel 显示默认的 2x2 网格,复选框位于一个奇怪的位置。运行后,控件显示正确(3x8 网格,复选框位于正确位置) - 并且:在Form的InitializeComponent()中,我看到这些行出现了:
//
// tableLayoutPanelHours1
//
this.tableLayoutPanelHours1.ColumnCount = 8;
this.tableLayoutPanelHours1.ColumnCount = 3;
this.tableLayoutPanelHours1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
// ....
我已经排除了这些行在 Windows 窗体的 InitializeComponent() 中不可见,但为什么会发生这种情况?
谢谢。
【问题讨论】: