PictureBox上的动态点击事件 [英] Dynamic click event on PictureBox

查看:70
本文介绍了PictureBox上的动态点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从目录中获取图片列表,并将文件名存储在 List< String> 中.然后,我遍历所有这些对象,并为每个对象创建一个 PictureBox ,然后向每个对象添加相同的click事件.控件位于 FlowLayoutPanel

I am getting a list of pictures from a directory and storing the filenames in a List<String>. I then loop through each of these and create a PictureBox for each of them, I then add the same click event to each. The controls are in a FlowLayoutPanel

foreach(String file in this._files){
    PictureBox box = new PictureBox();
    box.Height = 50;
    box.Width = 50;
    box.ImageLocation = file;
    box.SizeMode = PictureBoxSizeMode.Zoom;
    box.Click += this.PictureClick;

    this.flowLayoutPanel1.Controls.Add(box);
}

private void PictureClick(object sender, EventArgs e){
    // how do I get the one that has been clicked and set its border color
}

如何获取被单击的那个并设置其边框颜色?

How do I get the one that has been clicked and set its border color?

推荐答案

发件人是所单击的 PictureBox :

private void PictureClick(object sender, EventArgs e) {
    PictureBox oPictureBox = (PictureBox)sender;
    // add border, do whatever else you want.
}

这篇关于PictureBox上的动态点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆