winform tablelayoutpanel用法
(最新版)
1.WinForm 概述 
2.TableLayoutPanel 简介 
3.TableLayoutPanel 的基本属性 
4.TableLayoutPanel 的事件 
5.TableLayoutPanel 的常用方法 
6.TableLayoutPanel 的实例应用
正文
【WinForm 概述】 
WinForm(Windows Forms)是.NET Framework 中的一种 Windows 应用程序开发技术,它允许开发人员使用可视化编程的方式构建具有丰富用户界面的应用程序。在 WinForm 中,有许多控件可以满足不同需求,TableLayoutPanel 就是其中之一。
【TableLayoutPanel 简介】 
TableLayoutPanel 是一个用于创建具有自动缩放和排列功能的表格式控件。它可以将控件以表格的形式组织,并且当窗口大小改变时,表格中的控件会自动调整大小以适应新的窗口尺寸。TableLayoutPanel 广泛应用于需要显示大量数据的场景,例如数据表格、文件资源管理器等。
【TableLayoutPanel 的基本属性】 
以下是 TableLayoutPanel 的一些基本属性:
1.Name:设置或获取 TableLayoutPanel 的名称。 
2.Parent:设置或获取 TableLayoutPanel 的父控件。 
3.BackColor:设置或获取 TableLayoutPanel 的背景。 
4.ForeColor:设置或获取 TableLayoutPanel 的前景。 
5.ColumnCount:获取 TableLayoutPanel 的列数。 
6.RowCount:获取 TableLayoutPanel 的行数。 
7.ColumnWidth:设置或获取指定列的宽度。 
8.RowHeight:设置或获取指定行的高度。 
9.CellSpacing:设置或获取表格单元格之间的间距。 
10.CellPadding:设置或获取表格单元格内部的间距。
【TableLayoutPanel 的事件】 
TableLayoutPanel 支持以下事件:
1.Load:在 TableLayoutPanel 加载时触发。 
2.Resize:在 TableLayoutPanel 大小改变时触发。 
3.Click:在 TableLayoutPanel 上单击时触发。 
4.DoubleClick:在 TableLayoutPanel 上双击时触发。 
5.MouseDown:在 TableLayoutPanel 上按下鼠标键时触发。 
6.MouseUp:在 TableLayoutPanel 上释放鼠标键时触发。 
7.MouseMove:在 TableLayoutPanel 上移动鼠标时触发。
【TableLayoutPanel 的常用方法】 
以下是 TableLayoutPanel 的一些常用方法:
1.AddRow(int index, int count):在指定位置添加一行或多行。 
2.AddColumn(int index, int count):在指定位置添加一列或多列。 
3.RemoveRow(int index, int count):删除指定位置的一行或多行。 
4.RemoveColumn(int index, int count):删除指定位置的一列或多列。 
mousemove是什么键
5.InsertRow(int index, int count):在指定位置插入一行或多行。 
6.InsertColumn(int index, int count):在指定位置插入一列或多列。 
7.RemoveAt(int index):删除指定位置的控件。 
8.Clear:清除 TableLayoutPanel 中的所有控件。
【TableLayoutPanel 的实例应用】 
以下是一个简单的 TableLayoutPanel 实例:
```csharp 
using System; 
using System.Windows.Forms;
public class MainForm : Form 
{
    public MainForm() 
    { 
        TableLayoutPanel tableLayoutPanel = new TableLayoutPanel(); 
        tableLayoutPanel.BackColor = Color.LightBlue; 
        tableLayoutPanel.ForeColor = Color.Black; 
        tableLayoutPanel.ColumnCount = 2; 
        tableLayoutPanel.RowCount = 2; 
        tableLayoutPanel.CellSpacing = 5; 
        tableLayoutPanel.CellPadding = 5;
        tableLayoutPanel.AddRow(0, 1); 
        tableLayoutPanel.AddRow(1, 1);
        tableLayoutPanel.AddColumn(0, 1); 
        tableLayoutPanel.AddColumn(1, 1);
        for (int i = 0; i < tableLayoutPanel.RowCount; i++) 
        { 
            for (int j = 0; j < tableLayoutPanel.ColumnCount; j++) 
            { 
                Button button = new Button(); 
                button.Text = "Cell " + i.ToString() + "," + j.ToString(); 
                tableLayoutPanel.Controls.Add(button, i, j); 
            } 
        }
        this.Controls.Add(tableLayoutPanel); 
    } 
}
```
以上代码创建了一个包含 4 个按钮的 TableLayoutPanel 实例,按钮分别位于不同的单元格中。