Change your imgSelected to something like:
private PictureBox picSelected = null;
On your sample, click this variable for the sender:
picSelected = (PictureBox)sender;
Then, when you click the form button or control with focus, you run the image deletion code (Example for the form):
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
picSelected.Image = null;
}
source
share