【发布时间】:2020-08-03 21:27:44
【问题描述】:
我是 C# 新手,想根据一个轨迹栏值更改一些图片框的大小。 如果我编写下面的代码引用一个特定的图片框(例如 Picturebox1 而不是 PB)它可以工作,但我想对我双击的所有图片框使用一个双击事件。
下面的代码给出了 PB = null。 我得到了选定的图片框名称,但我怎样才能引用这个图片框?
'''
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#
谢谢
【问题讨论】:
标签: c# resize picturebox selected