winform tabellayoutpnel 大小可调整怎么实现
时间: 2024-05-10 19:20:51 浏览: 12
WinForm TableLayoutPanel 的大小可调整可以通过以下步骤实现:
1. 在设计时,将 TableLayoutPanel 的 Dock 属性设置为 Fill,使其始终填充其容器。
2. 启用 TableLayoutPanel 的自动调整大小功能。在属性窗口中,将 AutoSize 属性设置为 True,并将 AutoSizeMode 属性设置为 GrowAndShrink。
3. 在 TableLayoutPanel 的每个单元格中添加需要调整大小的控件,并将其 Dock 属性设置为 Fill。
4. 在 TableLayoutPanel 上添加一个 Splitter 控件。Splitter 控件允许用户手动调整 TableLayoutPanel 的大小。
5. 设置 Splitter 控件的 Dock 属性为 Bottom 或 Right,使其与 TableLayoutPanel 接触。
6. 确保 Splitter 控件的 Anchor 属性设置为 Top 或 Left,并将其 MinimumSize 属性设置为适当的值。
7. 在 Splitter 控件的 Moved 事件中,重新调整 TableLayoutPanel 和其子控件的大小。
示例代码如下:
```
private void splitter1_Moved(object sender, EventArgs e)
{
tableLayoutPanel1.Height = tableLayoutPanel1.Height + splitter1.Height - splitter1.PreviousBounds.Height;
foreach (Control control in tableLayoutPanel1.Controls)
{
control.Height = tableLayoutPanel1.RowStyles[tableLayoutPanel1.GetRow(control)].Height - control.Margin.Top - control.Margin.Bottom;
}
}
```
在以上示例代码中,我们在 Splitter 控件的 Moved 事件中重新调整了 TableLayoutPanel 和其子控件的大小。我们首先调整 TableLayoutPanel 的高度,然后遍历 TableLayoutPanel 的每个子控件,重新调整每个子控件的高度以适应新的单元格高度。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)