tableLayoutPanel
(ツールボックスから追加された10x10の列と行のサイズ)があり、すべてのセルにシングルを追加しPanel
たので、2つのオブジェクト/コンポーネントをセルに追加できました。すべてのセルには alabel
と aが含まれていbutton
ます。panel
問題は、プログラムで 2 つのコンポーネントを に追加できなかったことです。私は何をすべきか?
これが私のコードです:
private int[,] grid;
private Button[,] btn_grid;
private Label[,] lbl_grid;
private int timer = 0;
private Panel[,] pnl_grid;
private bool createGrid()
{
Random rnd1 = new Random();
grid = new int[width, height];
pnl_grid = new Panel[width, height];
btn_grid = new Button[width, height];
lbl_grid = new Label[width, height];
for (int x = 0; x <width; x++)
{
for (int y = 0; y < height; y++)
{
btn_grid[x, y] = createButton(x, y);
lbl_grid[x, y] = createLables(x,y);
pnl_grid[x, y] = createPanels(x, y);
**//something's missing here to add the 2 components into a panel**
tableLayoutPanel2.Controls.Add(pnl_grid[x,y]);
}
}}
private Button createButton(int gridX, int gridY)
{
Button bttn = new Button();
bttn.Text = "";
bttn.Name = gridX.ToString() + " " + gridY.ToString();
bttn.Size = new System.Drawing.Size(30, 30);
Controls.AddRange(new System.Windows.Forms.Control[] { bttn, });
bttn.Click += new System.EventHandler(bttnOnclick);
//bttn.MouseClick += new System.Windows.Forms.MouseEventHandler(this.bttnOnRightClick);
return bttn;
}
private Label createLables(int gridX, int gridY)
{
Label lbl = new Label();
lbl.Name = gridX.ToString() + " " + gridY.ToString();
lbl.Text = "0";
lbl.Size = new System.Drawing.Size(30, 30);
//lbl.Font = new Font("Microsoft Sans Serif", 15.75f, lbl.Font.Style, lbl.Font.Unit);
Controls.AddRange(new System.Windows.Forms.Control[] { lbl, });
return lbl;
}
private Panel createPanels(int gridX, int gridY)
{
Panel pnl = new Panel();
pnl.Name = gridX.ToString() + " " + gridY.ToString();
//pnl.Text = "0";
pnl.Size = new System.Drawing.Size(30, 30);
//lbl.Font = new Font("Microsoft Sans Serif", 15.75f, lbl.Font.Style, lbl.Font.Unit);
Controls.AddRange(new System.Windows.Forms.Control[] { pnl, });
return pnl;
}
あなたの感謝の注意と助けに感謝します!