簡體   English   中英

動態添加的控件不會顯示在窗體上

[英]Controls added dynamically won't show on form

我將控件添加到我的窗體上,該控件由數組中的位置指定。 我嘗試過將面板切換為按鈕,但控件仍未顯示。

int[,] gamefield = new int[9, 8];
Panel[,] vis_gamefield = new Panel[9, 8];

private void Real_Move(int col) 
    {
        for (int i = 6; i > 0; i--)
        {
            gamefield[col, i] = 1;
            vis_gamefield[col, i] = new Panel();
            vis_gamefield[col, i].Name = "Panel" + moves;
            vis_gamefield[col, i].BackColor = Color.Red;
            vis_gamefield[col, i].Size = new Size(88, 88);
            vis_gamefield[col, i].Location = new Point(158 + 100 * (i - 1), 174 + 99 * (col - 1));
            vis_gamefield[col, i].Visible = true;
            vis_gamefield[col, i].BringToFront();
            vis_gamefield[col, i].Show();
            Win_Check(col, i);
            moves++;
            break;
        }

    }

尚不清楚您如何將vis_gamefield准確地添加到窗體控件集合中?

您是否有一行這樣的this.Controls.Add(vis_gamefield); 在表單構造函數中?

它應該看起來像下面的代碼

public Form1()         
{
    InitializeComponent(); 
    this.Controls.Add(vis_gamefield);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM