foreach (Control pControl in Controls)
{
if (pControl is Panel)
{
foreach (Control IControl in pControl.Controls)
{
if (IControl is PictureBox)
{
//IControl.Click += this.Image_Click;
IControl.Click += new System.EventHandler(this.Image_Click);
}
}
}
}
}
这一段代码是form_load中的,是遍历所有的picturebox控件,并加载相应的委托事件,如我下面写的。
但效果不理想,我只要点其中任何一个picturebox,会把所有的picturebox都单击一遍,所以我想在上面一段代码
传个参数给下面的代码,希望高人给点指点。拜谢。
foreach (Control pControl in Controls)
{
if (pControl is Panel)
{
foreach (Control IControl in pControl.Controls)
{
if (IControl is PictureBox)
{
if (IControl.Name.Length == 11)
{
int PictureIndex = Convert.ToInt32(IControl.Name.Substring(10, 1));
this.dataGridViewRegList(PictureIndex - 1);
}
if (IControl.Name.Length == 12)
{
int PictureIndex = Convert.ToInt32(IControl.Name.Substring(10, 2));
this.dataGridViewRegList(PictureIndex - 1);
}
}
}
}
}
{
if (pControl is Panel)
{
foreach (Control IControl in pControl.Controls)
{
if (IControl is PictureBox)
{
//IControl.Click += this.Image_Click;
IControl.Click += new System.EventHandler(this.Image_Click);
}
}
}
}
}
这一段代码是form_load中的,是遍历所有的picturebox控件,并加载相应的委托事件,如我下面写的。
但效果不理想,我只要点其中任何一个picturebox,会把所有的picturebox都单击一遍,所以我想在上面一段代码
传个参数给下面的代码,希望高人给点指点。拜谢。
foreach (Control pControl in Controls)
{
if (pControl is Panel)
{
foreach (Control IControl in pControl.Controls)
{
if (IControl is PictureBox)
{
if (IControl.Name.Length == 11)
{
int PictureIndex = Convert.ToInt32(IControl.Name.Substring(10, 1));
this.dataGridViewRegList(PictureIndex - 1);
}
if (IControl.Name.Length == 12)
{
int PictureIndex = Convert.ToInt32(IControl.Name.Substring(10, 2));
this.dataGridViewRegList(PictureIndex - 1);
}
}
}
}
}
{
int PictureIndex = Convert.ToInt32(IControl.Name.Substring(10, 1));
this.dataGridViewRegList(PictureIndex - 1);
}
if ((sender as Control).Name.Length == 12)
{
int PictureIndex = Convert.ToInt32(IControl.Name.Substring(10, 2));
this.dataGridViewRegList(PictureIndex - 1);
}