缩放 WinForms TableLayoutPanel

发布于 2024-09-13 22:05:18 字数 862 浏览 11 评论 0原文

我对 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));
}

感谢您的帮助。

I have an issue with TableLayoutPanel, which fills an 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). I change this controler size using Bounds property.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2024-09-20 22:05:18

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

For each row, add an item to the TableLayoutPanel's RowStyles collection with SizeType = SizeType.Percent and Height = 100 / tableLayoutPanel.RowCount. Do the same with the ColumnStyles collection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文