所以我填充图像的浮动布局面板,使用此代码:
private void FillPanel(string sql)
{
panel.Controls.Clear();
SQLiteConnection dbConnect = new SQLiteConnection("Data Source=" + dbFullPath + ";Version=3;");
dbConnect.Open();
SQLiteCommand runQuery = new SQLiteCommand(sql, dbConnect);
SQLiteDataReader reader = runQuery.ExecuteReader();
while (reader.Read())
{
PictureBox pB = new PictureBox();
pB.Image = Image.FromFile(reader["imgPath"].ToString());
pB.Size = new Size(100, 100);
pB.SizeMode = PictureBoxSizeMode.StretchImage;
pB.Padding = new Padding();
pB.Margin = new Padding(5,5,5,5);
pB.Name = reader["name"].ToString();
toolTip_Main.SetToolTip(pB, pB.Name);
pB.DoubleClick += img_DoubleClick;
panel.Controls.Add(pB);
}
dbConnect.Close();
}
如果我尝试删除源的图片后,我得到的errormessage的。
“image.png被另一个过程”
要删除我用下面的代码的图片:
private void Delete()
{
foreach (Control x in panel.Controls)
{
if (x is PictureBox)
{
PictureBox pb = x as PictureBox;
string name = pb.Name;
DirectoryInfo pF = new DirectoryInfo(pictureFolder);
foreach (FileInfo file in pF.GetFiles())
{
if(file.Name == name+".png")
{
pb.InitialImage = null;
pb.Dispose();
file.Delete();
break;
}
}
}
}
}
如果我不填充图像的面板,我能够删除它们。 我只是不知道我接下来会做些什么,以“initialimage = NULL”&.dispose到盖茨摆脱面板内的图像。
但似乎他们是重影的地方。
在这个任何想法?