简体   繁体   English

扩展WinForms TableLayoutPanel

[英]Scaling WinForms TableLayoutPanel

I have an issue with TableLayoutPanel, which fills an userControl (DockStyle.Fill). 我有一个TableLayoutPanel的问题,填充userControl(DockStyle.Fill)。 I face a trouble, when this control is being resized, I need all cells to change their size, but only last row and last column changes size (so whole tableLayoutPanel fills the control). 我遇到麻烦,当调整此控件的大小时,我需要所有单元格来改变它们的大小,但只有最后一行和最后一列改变大小(所以整个tableLayoutPanel填充控件)。 I change this controler size using Bounds property. 我使用Bounds属性更改此控制器大小。

let's say I wrote following code: 假设我写了以下代码:

// 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));
}

Thanks for any help. 谢谢你的帮助。

For each row, add an item to the TableLayoutPanel 's RowStyles collection with SizeType = SizeType.Percent and Height = 100 / tableLayoutPanel.RowCount . 对于每一行,使用SizeType = SizeType.PercentHeight = 100 / tableLayoutPanel.RowCount将项添加到TableLayoutPanelRowStyles集合中。 Do the same with the ColumnStyles collection. ColumnStyles集合执行相同的ColumnStyles

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM