I have tried using Tag
, Name
, Text
, IndexOf
. Every time, I get the first name and that's it. Here is the code:
// Perform scanning
for (;;)
{
List<System.Drawing.Image> images = this.ScannerDevice.PerformScan().ToList();
// Show picture in window
this.Invoke((MethodInvoker)delegate
{
this.FrontImage = images[0];
foreach (System.Drawing.Image image in images)
{
PictureBox pf = new PictureBox();
pf.SizeMode = PictureBoxSizeMode.StretchImage; pf.Height = 150; pf.Width = 170;
pf.Image = image;
pf.Click += new EventHandler(pictureClicked);
flowLayoutPanel1.Controls.Add(pf);
pf.Tag=flowLayoutPanel1.Controls.Count;
}
ScanFinishedEventArgs eventArgs = new ScanFinishedEventArgs { AcceptScan = true };
this.ScanFinished?.Invoke(this, eventArgs);
label1.Text = Convert.ToString(flowLayoutPanel1.Controls.Count);
});
}
void pictureClicked(object sender, EventArgs e)
{
if (selectedPicture != null)
selectedPicture.BorderStyle = BorderStyle.None;
selectedPicture = (PictureBox)sender;
selectedPicture.BorderStyle = BorderStyle.FixedSingle;
pictureBox1.Image = selectedPicture.Image;
label2.Text = Convert.ToString(pf.Tag);
}
Also I would like to use that name later to be displayed in another label when I click on the certain picturebox.
Also I have tried using anonymous types
but unable to use it with image objects. What am I doing wrong?