用c#编程的方式点击tableayoutpanel

本文关键字:tableayoutpanel 方式点 编程 | 更新日期: 2023-09-27 17:53:27

我想以编程方式创建一个TableLayoutPanel。我做了,它工作了,显示都正确。现在我想添加Click或MouseClick事件但它没有触发。这是我的代码:

private void CreateTable()
{
    this.SuspendLayout();
    if (table == null)
        GenerateTable();
    else
        table.Controls.Clear();
    ResizeTable();
    CreateRowStyles();
    CreateColumnStyles();
    GenerateColumnHeaders();
    GenerateRows();
    Controls.Add(table);
    this.ResumeLayout();
}

表生成:

private void GenerateTable()
{
    table = new TableLayoutPanel()
    {
        RowCount = 1 + rowCount,
        ColumnCount = 1 + columnCount,
        Location = new Point(0, 0),
        BackColor = Color.White,
        Size = new Size(this.Width, this.Height),
        GrowStyle = TableLayoutPanelGrowStyle.FixedSize
    };
    table.MouseClick += new MouseEventHandler(table_MouseClick);
}

table_MouseClick:

void table_MouseClick(object sender, MouseEventArgs e)
{
    Debug.WriteLine("h");
}

有什么问题吗?我错过什么了吗?

用c#编程的方式点击tableayoutpanel

试试这个:

 table.MouseClick += new MouseEventHandler(table_MouseClick);