【问题标题】:Adding pictureBox to panel with codes使用代码将图片框添加到面板
【发布时间】:2016-05-13 14:36:47
【问题描述】:

我在 Visual Studio/windows 窗体应用程序中有一个面板。但我无法使用代码在其上添加图片框。如果我在没有面板的情况下工作,但我需要它。MyCodes:

      PictureBox[] pipe = new PictureBox[3];

 private void Form1_Load(object sender, EventArgs e)
    {
        CreatePipes(1);}

    private void CreatetopPipes(int Number)
    {
          for (int i = 0; i <= Number; i++)
        {

            PictureBox temp = new PictureBox();
            this.Controls.Add(temp);
            temp.Width = 50;
            temp.Height = 350;
            temp.BorderStyle = BorderStyle.FixedSingle;
            temp.BackColor = Color.Red;
            temp.Top = 30;
            temp.Left = 300;
            topPipe[i] = temp;
            topPipe[i].Visible = true;


        }
    }

【问题讨论】:

  • this - 是Form。请改用您的面板。
  • 并且不要将它们全部堆叠在同一个位置!

标签: c# winforms panel picturebox


【解决方案1】:

您可以使用panelName.Controls.Add(temp),我建议您将PictureBox 的顶部更改为for loop 以查看所有PictureBox,如下所示:

private void CreatetopPipes(int Number)
{
    for (int i = 0; i <= Number; i++)
    {

        PictureBox temp = new PictureBox();
        panelName.Controls.Add(temp);
        temp.Width = 50;
        temp.Height = 350;
        temp.BorderStyle = BorderStyle.FixedSingle;
        temp.BackColor = Color.Red;
        temp.Top = temp.Height * panelName.Controls.Count;
        temp.Left = 300;
        topPipe[i] = temp;
        topPipe[i].Visible = true;

    }
}

【讨论】:

    猜你喜欢
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 2015-10-27
    • 2010-10-16
    相关资源
    最近更新 更多