I have a PictureBox on my user control and I have added lots of this User Control on my form. Thing is whenever a user clicks on PictureBox he should get that User Control item to which this PictureBox belongs.
So, on my User Control I have added this code
public usercontrol1()
{
InitializeComponent();
pictureBox1.Parent = this;
}
Then on my Form
private void form1_Load(object sender, EventArgs e)
{
var c = new usercontrol1();
c.pictureBox1.Click += item_click;
c = new usercontrol1();
c.pictureBox1.Click += item_click;
}
private void item_click(object sender, EventArgs e)
{
usercontrol1 abc = pictureBox1.Parent; // Giving Error
}
I tried this approach to set user control as parent control of picturebox and tried to retrieve it from picturebox click event on form. But resulting in failure. How do I get the usercontrol1 object from PictureBox click event?