小编Sta*_*Who的帖子

用户在运行时调整TableLayoutPanel中行和列的大小

我正在研究WinForm项目,并“尝试”创建一个TableLayoutPanel,用户可以在运行时调整大小,例如SplitContainer的行为。我发现一些代码可以部分执行此操作,但是它不完整。有人可以帮我吗?

在此先感谢-DA

到目前为止,这是我在CodeProject上找到的线程中提供的代码。我自己所做的唯一不同是创建一个从TableLayoutPanel继承的customTableLayoutPanel。

public partial class Form1 : Form
{
    bool resizing = false;
    TableLayoutRowStyleCollection rowStyles;
    TableLayoutColumnStyleCollection columnStyles;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        rowStyles = tableLayoutPanel1.RowStyles;
        columnStyles = tableLayoutPanel1.ColumnStyles;
    }

    private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            resizing = true;
        }
    }

    private void tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (resizing)
        {
            columnStyles[0].SizeType = SizeType.Absolute;
            rowStyles[0].SizeType = SizeType.Absolute;
            rowStyles[0].Height = e.Y;
            columnStyles[0].Width = e.X;
        }
    }

    private void …
Run Code Online (Sandbox Code Playgroud)

c# winforms

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

winforms ×1