pic.Click += 你的事件处理函数
解决方案 »
- ASP.NET出现缺少根元素错误,就算是刚刚新建的一个WEB项目也这样。
- 用C#连接SQL server2005 的连接字符串怎么写
- 如何实现自动输入的功能?
- 【求助】帮忙看看代码
- C#用gif动画光标的问题
- Specified argument was out of the range of valid values. Parameter name: index
- WinForm中comboBox可以邦定2维数组么,如何邦定?
- 串口编程高手帮忙
- 请教大家:为何我的.net web服务器达到一定访问量的时候出现“服务器太忙”??
- CreateFile中的参数dwDesiredAccess 是多少?
- 大神进来帮一下
- VS2010调试的问题
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)=>{...//处理逻辑};
}
private void pic_Click(object sender, EventArgs e)
{ }
然后pic.Click+=pic_Click;
对吗?
{
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的值怎么才能取到当前点击的图片呢
{
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值了
要不直接picture1.tag就可以了。
private void pic_Click(object sender, EventArgs e)
{
Image img=(Image) sender;
label1.Text=imageList1.Img.Tag.ToString();
}我猜的,也许有用
{
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;
}