代码如下:
while(myReader.Read())
{
string startpath=Application.StartupPath;
string PrePicPath=startpath+myReader.GetString(1);
FileStream fs=new FileStream(PrePicPath,FileMode.Open,FileAccess.Read);
pB1.Image=Image.FromStream(fs);
fs.Close();
}
问题:form上有多个picturebox(分别为pB1,pB2,pB3......),我想从datareader里读取每一行就把读出的图片路径赋给一个picturebox,不知道这个pB1,pB2,pB3......怎么写入到循环里去,大家帮忙,谢谢了。
while(myReader.Read())
{
string startpath=Application.StartupPath;
string PrePicPath=startpath+myReader.GetString(1);
FileStream fs=new FileStream(PrePicPath,FileMode.Open,FileAccess.Read);
pB1.Image=Image.FromStream(fs);
fs.Close();
}
问题:form上有多个picturebox(分别为pB1,pB2,pB3......),我想从datareader里读取每一行就把读出的图片路径赋给一个picturebox,不知道这个pB1,pB2,pB3......怎么写入到循环里去,大家帮忙,谢谢了。
while(myReader.Read())
{
i += 1;
string startpath=Application.StartupPath;
string PrePicPath=startpath+myReader.GetString(1);
FileStream fs=new FileStream(PrePicPath,FileMode.Open,FileAccess.Read);
PictureBox pic = GetPictureBoxByName("pB" + i.ToString());
if (pic != null)
{
pic.Image = Image.FromStream(fs);
}
fs.Close();
}private PictureBox GetPictureBoxByName(string picName)
{
foreach (Control c in this.Controls)
{
if (c.Name == picName)
{
if (c.GetType().FullName == "System.Windows.Forms.PictureBox")
return (PictureBox)c;
}
}
return null;
}