if (result1 == DialogResult.Yes)
{
if (listBox1.SelectedItems.Count > 0)
{
string FileName = "";
FileName = listBox1.SelectedItems[0].ToString();
listBox1.Items.Remove(listBox1.SelectedItems[0]);
string path = Application.StartupPath @"\Image\" + FileName;
if (File.Exists(path))
{
File.Delete(path);
}
pictureBox1.Image = null;
pictureBox2.Image = null;
textBox1.Text = "";
MessageBox.Show("File Successfully Removed.");
}
}
change the while for an if. You are trying to delete it multiple times now.
Also the else is not necesarry you can delete it.