【问题标题】:Controls added dynamically won't show on form动态添加的控件不会显示在表单上
【发布时间】:2018-08-14 21:20:19
【问题描述】:

我将控件添加到表单中由它们在数组中的位置指定的位置。我已尝试将面板切换为按钮,但控件仍未显示。

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;
        }

    }

【问题讨论】:

  • I'm adding controls onto my form 不,您似乎忘记向控件集合添加任何内容
  • 您忘记将面板添加到父级,考虑this.Controls.Add(vis_gamefield[col, i]);

标签: c# .net winforms


【解决方案1】:

有点不清楚你是如何将 vis_gamefield 添加到表单控件集合中的?

在 Form 构造函数中是否有类似 this.Controls.Add(vis_gamefield); 的行?

它应该类似于下面的代码

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    相关资源
    最近更新 更多