PictureBox上的动态点击事件

CR4*_*G14 0 .net c#

我从一个目录中获取一个图片列表,并将文件名存储在一个List<String>.然后我循环遍历其中的每一个并PictureBox为每个创建一个,然后我为每个添加相同的click事件.控件在一个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
}
Run Code Online (Sandbox Code Playgroud)

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

小智 5

senderPictureBox被点击的:

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