The
sender
parameter of the event handler is there for just that reason:
private void form_MouseClick(object sender, EventArgs e)
{
PictureBox pb = sender as PictureBox;
if (pb != null)
{
folderBrowser.ShowDialog();
string filepath = folderBrowser.SelectedPath;
Image im = pb.Image;
var obj = new Random();
SaveImage(im, filepath + "\\" + obj.Next() + ".png");
}
}