点击了一个生成的图片框。我想知道哪一个被点击了。我想知道“我”。点击完成后工人的价值。 [英] One of the resulting pictureboxes was clicked. I want to know which one is clicked. I want to know the "I" value of the worker when the click is done.

查看:64
本文介绍了点击了一个生成的图片框。我想知道哪一个被点击了。我想知道“我”。点击完成后工人的价值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







for (int i = 0; i < 3; i++)
 {
     worker[i] = new PictureBox();
     worker[i].Name = "isci-" + i.ToString();
     worker[i].Location = new Point(10 + i, 20);
     worker[i].ImageLocation = "D:\\Proje Resim\\Folder.PNG";
     worker[i].Width = 150;
     worker[i].Height = 120;
     worker[i].Visible = true;
     worker[i].BackColor = Color.Transparent;
     worker[i].SizeMode = PictureBoxSizeMode.StretchImage;

     flowLayoutVideo.Controls.Add(worker[i]);
     worker[i].DoubleClick += new EventHandler(workerStart_Click);





我的尝试:



点击了一个生成的PictureBox。我想知道哪一个被点击了。我想知道点击完成后工人的i值。请帮帮我。



What I have tried:

One of the resulting PictureBoxes was clicked. I want to know which one is clicked. I want to know the "i" value of the worker when the click is done. Help me Please.

推荐答案

最简单的方法是使用PictureBox的Tag属性(所有Control派生类都有Tag属性)并将其设置为i的值:

Easiest way is to use the Tag property of the PictureBox (all Control derived classes have a Tag property) and set it to the value of i:
worker[i] = new PictureBox();
worker[i].Tag = i;
worker[i].Name = "isci-" + i.ToString();

然后在Click处理程序中:

Then in the Click handler:

void allPictureBoxes_Click(object sender, EventArgs e)
    {
    PictureBox p = sender as PictureBox;
    if (p != null)
        {
        int i = (int) p.Tag;
        ...
        }
    }


这篇关于点击了一个生成的图片框。我想知道哪一个被点击了。我想知道“我”。点击完成后工人的价值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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