I wanted to create a TableLayoutPanel programmatically. 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. 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:
void table_MouseClick(object sender, MouseEventArgs e)
{
Debug.WriteLine("h");
}
Is there anything wrong? I missed anything? 0 events working with the table.
尝试这个:
table.MouseClick += new MouseEventHandler(table_MouseClick);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.