pic.Click += 你的事件处理函数

解决方案 »

  1.   

    是的,在你的for循环里面加1楼的代码,方法逻辑自己处理下即可。
     for (int i = 0; i < imageList1.Images.Count; i++)
                {
                    PictureBox pic = new PictureBox();
                    this.Controls.Add(pic);
                    pic.Size = new System.Drawing.Size(139, 102);
                    pic.Location = new System.Drawing.Point(1, loca);
                    pic.Image = imageList1.Images[i];
                    
                    loca += 108;
                    
                    pic.Click+=(ss,ee)=>{...//处理逻辑};
                }
      

  2.   

    没看懂、我是要这样再建一个方法吗?
    private void pic_Click(object sender, EventArgs e)
            {        }
    然后pic.Click+=pic_Click;
    对吗?
      

  3.   

    private void pic_Click(object sender, EventArgs e)
            {
                string strConnect = "data source=.;initial catalog=test;integrated security=true";
                SqlConnection conConnection = new SqlConnection(strConnect);
                conConnection.Open();
                string sqlStr = "select picture from picture";
                SqlDataAdapter myAdapter = new SqlDataAdapter(sqlStr, conConnection);
                DataSet mydataSet = new DataSet();
                myAdapter.Fill(mydataSet, "test_user");
                conConnection.Close();
               label1.Text=mydataSet.Tables["test_user"].Rows[i]["picture"].ToString();
            }
    Row[i]里i的值怎么才能取到当前点击的图片呢
      

  4.   

    你把imageList1.Images[i].Tag="这里面存放学生的学号",然后在方面里面取一下,查一下对应的信息给文本框赋值就可以了;
      

  5.   

    for (int i = 0; i < imageList1.Images.Count; i++)
                {
                    imageList1.Images[i].Tag = "" + mydataSet.Tables["test_user"].Rows[i]["picture"].ToString() + "";
                    PictureBox pic = new PictureBox();
                    this.Controls.Add(pic);
                    pic.Size = new System.Drawing.Size(139, 102);
                    pic.Location = new System.Drawing.Point(1, loca);
                    pic.Image = imageList1.Images[i];
                    pic.Click += pic_Click;
                    loca += 108;
                }
                
            }        private void pic_Click(object sender, EventArgs e)
            {
                label1.Text=imageList1.Images[i].Tag.ToString();
            }
    又不知道怎么取i值了
      

  6.   

    关键是用代码建了了很多个pictureBox,又不知道他们的name是什么。
    要不直接picture1.tag就可以了。
      

  7.   


    private void pic_Click(object sender, EventArgs e)
            {
    Image img=(Image) sender;
                label1.Text=imageList1.Img.Tag.ToString();
            }我猜的,也许有用
      

  8.   

    把图片放在学生表中,然后把信息取出来  public class UserInfo
        {
    public string Name{get;set;}
    publie stringAddress{get;set;}
    ....................
    }string strConnect = "data source=.;initial catalog=test;integrated security=true";
                SqlConnection conConnection = new SqlConnection(strConnect);
                conConnection.Open();
                string sqlStr = "select  *  from users";
                SqlDataAdapter myAdapter = new SqlDataAdapter(sqlStr, conConnection);
                DataSet mydataSet = new DataSet();
                myAdapter.Fill(mydataSet, "test_user");
                conConnection.Close();
                imageList1.ImageSize = new Size(139, 102);
               DataTable userDt=mydataSet.Tables["test_user"];
                for (int i = 0; i < userDt.Rows.Count; i++)
                {
    UserInfo user=new UserInfo();
            DataRow dr=userDt.Rows[i];
                PictureBox pic = new PictureBox();
                    this.Controls.Add(pic);
                    pic.Size = new System.Drawing.Size(139, 102);
                    pic.Location = new System.Drawing.Point(1, loca);
                    pic.Image =Image.FromFile("" + dr[i]["picture"].ToString() + "")         
                    loca += 108;
    user.Name=dr[i]["Name"].ToString()
    user.Address=dr[i]["Address"].ToString()
        pic.Click += pic_Click;
                     pic.Tag=user;
                }     private void pic_Click(object sender, EventArgs e)
            {
    PictureBox pic=(PictureBox ) sender;
           UserInfo=(UserInfo)pic.Tag;
            }