简体   繁体   English

TableLayoutPanel MouseClick以C#编程方式

[英]TableLayoutPanel MouseClick programmatically in C#

I wanted to create a TableLayoutPanel programmatically. 我想以编程方式创建TableLayoutPanel。 I did it and it works and show all correctly. 我做到了,它可以正常显示所有内容。 But now I want to add a Click or MouseClick event but it doesn't fire. 但是现在我想添加一个Click或MouseClick事件,但是不会触发。 This is my code: 这是我的代码:

private void CreateTable()
{
    this.SuspendLayout();

    if (table == null)
        GenerateTable();
    else
        table.Controls.Clear();

    ResizeTable();

    CreateRowStyles();
    CreateColumnStyles();

    GenerateColumnHeaders();

    GenerateRows();

    Controls.Add(table);

    this.ResumeLayout();
}

Table generate: 表生成:

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: table_MouseClick:

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

Is there anything wrong? 有什么问题吗? I missed anything? 我错过了什么吗? 0 events working with the table. 该表有0个事件。

尝试这个:

 table.MouseClick += new MouseEventHandler(table_MouseClick);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM