您好我有一个使用按钮数组生成网格的小程序。单击按钮时,它们会改变颜色。我怎样才能将这个布局准确地导出到 Excel 女士中,它在表单上的样子甚至可能吗?我希望 Excel 中的单元格代表按钮
我的程序如下所示:
我如何创建我的网格:
int col = 7;
int row = 4;
int count = 0;
Button[][] buttons;
public void placeRows()
{
for (int r = 0; r < row; r++)
{
createColumns(r);
}
}
public void createColumns(int r)
{
int s = r * 25; //gap
for (int c = 0; c < col; c++)
{
buttons[r][c] = new Button();
buttons[r][c].SetBounds(75 * c, s, 75, 25);
buttons[r][c].Text = Convert.ToString(c);
buttons[r][c].Click += new EventHandler(grid_Click);
panel1.Controls.Add(buttons[r][c]);
}
}
private void Form1_Load(object sender, EventArgs e)
{
placeRows();
}
void grid_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (count == 0)
{
button.BackColor = Color.Red;
count++;
}
else if (count == 1)
{
button.BackColor = Color.Blue;
count--;
}
}
private void btnExport_Click(object sender, EventArgs e)
{
//have no idea how to start this
}