Zarei Ramin

my project has two form : form1 , form2

and form2 has some pictureboxes

i show form2 from form1, and i want know which pictuerbox was clicked after closing form2, in form. like following code:

form1 form=new form1();;




string s=form.selectedpictureboxname(); // variable in form1

Re: Windows Forms General Working Between forms


Hi Zarei,

You can achieve this in following two steps

1. In the form you can declare one string variable and expose it using public properties. Then set this string variable in the click event of the PicutreBox as follows:

Code Snippet

private string m_strPictureBoxClicked;

public string PictureBoxClicked


get { return m_strPictureBoxClicked; }

set { m_strPictureBoxClicked = value; }


private void pictureBox1_Click(object sender, EventArgs e)


m_strPictureBoxClicked = (sender as PictureBox).Name;


2. You can access this public property in following way:

Code Snippet

Form1 objForm = new Form1();



If no Picturebox was clicked then it will return an empty / null string.

Hope This Helps!