源代码中的WinForms C#Picturebox

源代码中的WinForms C#Picturebox,c#,winforms,output,picturebox,C#,Winforms,Output,Picturebox,如何使用源代码(无设计器)将Picturebox放入表单中? 我试过这个: PictureBox pb = new PictureBox(); pb.Size = new Size(10,10); pb.Location = new Point(10,10); pb.ImageLocation= @"C:\Users\user\Desktop\NoName\NoName\StandardPos.png"; pb.Load(); pb.Refresh(); pb.Sho

如何使用源代码(无设计器)将Picturebox放入表单中? 我试过这个:

  PictureBox pb = new PictureBox();
  pb.Size = new Size(10,10);
  pb.Location = new Point(10,10);
  pb.ImageLocation= @"C:\Users\user\Desktop\NoName\NoName\StandardPos.png";
  pb.Load();
  pb.Refresh();
  pb.Show();
但是我缺少了一些东西。

此说明:

pb.Parent=this


可能是pb.BringToFront()而不是Refresh And Show()。

您还没有将框添加到表单中:

        PictureBox pb = new PictureBox();
        pb.Size = new Size(100, 100);
        pb.Location = new Point(100, 100);
        pb.ImageLocation = @"C:\Users\user\Desktop\NoName\NoName\StandardPos.png";
        this.Controls.Add(pb);  //< add it to the form
PictureBox pb=新PictureBox();
pb.尺寸=新尺寸(100100);
pb.位置=新点(100100);
pb.ImageLocation=@“C:\Users\user\Desktop\NoName\NoName\StandardPos.png”;
此.Controls.Add(pb);//<将其添加到表单中
Google“C#以编程方式将控件添加到表单”的顶级结果。。。