如何在Windows窗体应用程序C#中以编程方式创建的PictureBox
分配事件处理程序?
编辑:
我试过这个,它给出了错误
没有重载pictureBox_MouseDown
this.ListFrameImage[i].MouseDown += new EventHandler(this.pictureBox_MouseDown);
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
someX = e.X;
someY = e.Y;
drag = true;
}
答案 0 :(得分:1)
只需使用+ =运算符添加事件处理程序:
pictureBox.MouseClick += new MouseEventHandler(your_event_handler);
或者:
pictureBox.MouseClick += new MouseEventHandler((o, a) => code here);
写+ =后按Tab键将生成处理程序。或者你可以写它 手动:
pictureBox.MouseClick += pictureBox_MouseClick;
void pictureBox_MouseClick(object sender, MouseEventArgs e)
{
// blah
}