이것은 당신을 가야합니다.
이 코드를 양식에 추가하십시오. 그리고이 코드를 원하는 버튼이나 원하는 것에 사용할 수 있습니다. 하지만 FlowLayoutPanel 또는 GroupBox를 읽어서 현실에서 작동하도록해야합니다.
Point _imagePos = new Point(10,10);
int _imageCounter = 1;
private void NewPictureBox(string pathToImg, string imageName)
{
var img = new PictureBox
{
Name = "imageBox" + _imageCounter,
ImageLocation = pathToImg,
Left = _imagePos.X,
Top = _imagePos.Y,
SizeMode = PictureBoxSizeMode.StretchImage,
Height = 50,
Width = 50
};
var txt = new TextBox
{
Text = imageName,
Left = _imagePos.X,
Top = img.Bottom + 10
};
this.Controls.Add(img);
this.Controls.Add(txt);
_imageCounter++;
_imagePos.Y += 10 + img.Height + txt.Height;
}
private void Form1_Load(object sender, EventArgs e)
{
NewPictureBox(@"C:\test\QuestionMark.jpg", "image1");
NewPictureBox(@"C:\test\QuestionMark.jpg", "image2");
}