我的panel控件里面有一个label控件和一个picturebox控件,我想点击某一个picturebox时,把picturebox的相应label的数据获取下来,然后把它传递到另一个窗口,怎么实现,求指导

解决方案 »

  1.   

    点击事件里你可以获取到sender,把它转换成Control
    然后用foreach遍历这个control.Parent.Controls,如果是Label就取它的数据
      

  2.   


            private void pictureBox1_Click(object sender, EventArgs e)
            {
                foreach(Control c in panel1.Controls )
                {
                    if(c is Label)
                    {
                        MessageBox.Show(c.Text);
                    }
                }
            }
      

  3.   

    可以直接把代码写给我吗?foreach(Control ctrl in (sender as PictureBox).Parent.Controls)
    {
        if(ctrl is Label)
           OtherForm.SetData(ctrl as Label);
    }