问题描述
Hello Friends,
我正在尝试在C#win中动态添加图片框。形成。它是bing loded,但当我想获得picturebox图像即。 PictureBox.Image然后它给我空值。假设我有20个图片框然后开始2-3 Picturebox.Image不是null但其余的是null ...
我的代码
private void button2_Click(object sender,EventArgs e)
{
if(folderpath.ShowDialog()== DialogResult.OK)
{
string path = folderpath.SelectedPath;
DirectoryInfo di = new DirectoryInfo(path);
FileInfo [] Images = di.GetFiles(*。jpg);
foreach(var img in Images)
{
PictureBox picture = new PictureBox
{
名称=pictureBox+ i,
尺寸=新尺寸(316,320),
位置=新点(i * 316, 1),
SizeMode = PictureBoxSizeMode.AutoSize
};
if(img.Name.Substring(0,5)==Errod)
{
picture.ImageLocation = img.FullName;
ErrodImg.Add(图片);
ErrodImgpanel.Controls.Add(图片);
}
其他
{
图片.ImageLocation = img.FullName;
OriginalImg.Add(图片);
OriginalImgpanel.Controls.Add(图片);
}
i ++;
}
}
}
请帮我解决这个问题
感谢Adv ance。
Hello Friends,
I am Trying to add the picturebox dynamically in my C# win. form. it is bing loded but when i am trying to get picturebox image ie. PictureBox.Image then it is giving me null value. Suppose i have 20 picturebox then starting 2-3 Picturebox.Image is not null but rest of are null...
My code
private void button2_Click(object sender, EventArgs e)
{
if (folderpath.ShowDialog() == DialogResult.OK)
{
string path = folderpath.SelectedPath;
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] Images = di.GetFiles("*.jpg");
foreach (var img in Images)
{
PictureBox picture = new PictureBox
{
Name = "pictureBox" + i,
Size = new Size(316, 320),
Location = new Point(i * 316, 1),
SizeMode = PictureBoxSizeMode.AutoSize
};
if (img.Name.Substring(0, 5) == "Errod")
{
picture.ImageLocation = img.FullName;
ErrodImg.Add(picture);
ErrodImgpanel.Controls.Add(picture);
}
else
{
picture.ImageLocation = img.FullName;
OriginalImg.Add(picture);
OriginalImgpanel.Controls.Add(picture);
}
i++;
}
}
}
please help me out for this problem
thanks in Advance.
推荐答案
这篇关于如何在picturebox中获取动态图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!