扩展WinForms TableLayoutPanel

时间:2010-08-10 18:10:05

标签: c# winforms tablelayoutpanel

我遇到了TableLayoutPanel的问题,它填充了userControl(DockStyle.Fill)。我遇到麻烦,当调整此控件的大小时,我需要所有单元格来改变它们的大小,但只有最后一行和最后一列改变大小(所以整个tableLayoutPanel填充控件)。我使用Bounds属性更改此控制器大小。

假设我写了以下代码:

// creating tableLayoutPanel:

private void createTableLayoutPanel(int count)
{
    tableLayoutPanel = new TableLayoutPanel();
    tableLayoutPanel.MouseClick += new MouseEventHandler(this.observe_MouseClick);
    tableLayoutPanel.AutoSize = true;
    tableLayoutPanel.ColumnCount = 3;
    tableLayoutPanel.RowCount = count;
    tableLayoutPanel.Dock = DockStyle.Fill;
    tableLayoutPanel.AutoSize = true;
    this.Controls.Add(tableLayoutPanel);
}

// resizing:

private void OnMouseWheel(MouseEventArgs e)
{
    this.Bounds = new Rectangle(this.Location.X, this.Location.Y, (int)(this.Width*newScale),(int)(this.Height*newScale));
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:4)

对于每一行,使用TableLayoutPanelRowStyles将一个项目添加到SizeType = SizeType.Percent的{​​{1}}集合中。对Height = 100 / tableLayoutPanel.RowCount集合执行相同的操作。