I am new to C# and want to change the size of some Pictureboxes based on one trackbar Value. If i write the below code refering to a spesific picturebox (e.g. Picturebox1 instead of PB) it works, but i would like to use one Doubleclick event for all Pictureboxes that i Doubleclick.
The below code gives PB = null. I get the selected Pictureboxname but how can i refer to this Picturebox?
'''
private void PictureBoxesDoubleClick(object sender, EventArgs e)
{
//get the selected Picturebox name
String PictureBoxName = ((PictureBox)sender).Name;
//This part doesn't work
PictureBox PB = (PictureBox)this.Controls[PictureBoxName];
//Resize the Picture box according to the trackBar Value
PB.Size = new Size(trackBar1.Value, trackBar1.Value);
PB.Left = (this.ClientSize.Width - pictureBox1.Width) / 2;
PB.Top = (this.ClientSize.Height - pictureBox1.Height) / 2;
}
'''
Which pictureBox was selected? C#
Thank you