private void btn_Delete_Click(object sender, EventArgs e) { List <int> imgList = new List <int>(); foreach (Control cmain in panel1.Controls) { if (cmain is Panel) { bool isChecked = false; foreach (Control c in cmain.Controls) { if (c is CheckBox && ((CheckBox)c).Checked) { isChecked = true; break; } } if (isChecked) { foreach (Control c in cmain.Controls) { if (c is PictureBox) { PictureBox pic = (PictureBox)c; if (pic.Image != null) { int id = Convert.ToInt32(pic.Tag); imgList.Add(id); } } } } } } if (imgList.Count > 0) { IUploadService us = FactoryService.CreateInstance(); int _failCount = us.DeleteImage(imgList.ToArray()); //int _failCount = dlService.RemoveImgsByThumbnail(imgList.ToArray()); if (_failCount > 0) { MessageBox.Show("删除完成,失败'" + _failCount + "'张"); } else { MessageBox.Show("删除完成"); } LoadService(); } }