astro
astro

Reputation: 45

Clicking on programmatically added pictureBox controls

I have a Winforms application where I programmatically add a number of pictureBox controls and load each one with an image.

How can I link each pictureBox control with a video file so I can run that video by clicking on that pictureBox control?

This is how I add my pictureBox controls:

if (ofd.ShowDialog() == DialogResult.OK)
        {
            file_address = ofd.FileName;
        }
var picture1 = new PictureBox

        {
            Name = "pictureBox",

            Size = new Size(160, 200),
            Location = new Point(x, y),
            SizeMode = PictureBoxSizeMode.Zoom,
            Image = Image.FromFile(file_address),
        };
 this.Controls.Add(picture1);

I've managed to add click event handler:

 picture1.Click += delegate
    {
            // Do something 
    }

Upvotes: 0

Views: 118

Answers (1)

dsum
dsum

Reputation: 1493

You can use the Tag property to store the file_address.

this.picture1.tag = file_address;

when you want to play the video by the picture box file name, get the file name by

string file_name = (string)this.picture1.tag;

Upvotes: 3

Related Questions