TableLayoutPanel MouseClick以C#

时间:2015-06-05 09:58:21

标签: c# events click tablelayoutpanel

我想以编程方式创建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");
}

有什么不对吗?我错过了什么?使用该表的0个事件。

1 个答案:

答案 0 :(得分:1)

试试这个:

 table.MouseClick += new MouseEventHandler(table_MouseClick);