【发布时间】:2014-05-15 03:05:22
【问题描述】:
我正在用 c# 编写 windows 窗体应用程序。
首先我在运行时创建了一个表格布局,然后在从数据库读取后插入图片框。现在我想在每个桌面单元格/图片框点击上编写 sql 查询。
首先,我尝试通过拖放插入图片框,然后在 picturebox_onclick 函数中编写查询。但是现在我正在运行时动态创建图片框。现在我如何处理我在运行时创建的图片框的 onclick 功能。
private void GenerateTable(int columnCount, int rowCount)
{
//Clear out the existing controls, we are generating a new table layout
tableLayoutPanel1.Controls.Clear();
//Clear out the existing row and column styles
tableLayoutPanel1.ColumnStyles.Clear();
tableLayoutPanel1.RowStyles.Clear();
//Now we will generate the table, setting up the row and column counts first
tableLayoutPanel1.ColumnCount = columnCount;
tableLayoutPanel1.RowCount = rowCount;
for (int x = 0; x < columnCount; x++)
{
//First add a column
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
for (int y = 0; y < rowCount; y++)
{
//Next, add a row. Only do this when once, when creating the first column
if (x == 0)
{
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
//Create the control, in this case we will add a button
picturebox cmd = new picturebox();
cmd.image = new bitmap("c:\\images\\abc.png");
tableLayoutPanel1.Controls.Add(cmd, x, y);
}
}
}
请建议我简单的方法,因为我是开发新手。提前致谢。
【问题讨论】:
标签: c# winforms tablelayout tablelayoutpanel