The Image
class has a Tag
property:
Gets or sets an object that provides additional data about the image.
var myImage = Bitmap.FromFile(@"c:\users\gwinney\desktop\9BYEo.jpg");
myImage.Tag = 4;
pictureBox1.Image = myImage;
var myNumber = Convert.ToInt32(pictureBox1.Image.Tag);
The PictureBox
has its own Tag
property:
Gets or sets the object that contains data about the control.
var myImage = Bitmap.FromFile(@"c:\users\gwinney\desktop\9BYEo.jpg");
pictureBox1.Image = myImage;
pictureBox1.Tag = 4;
var myNumber = Convert.ToInt32(pictureBox1.Tag);
You could also create a Dictionary
that holds meta data about each of your images. The key could be the name, or some other unique identifier about the image, then the value could be your number.
var myImageValues = new Dictionary<string, int>
{
{ "ImageOne", 1 },
{ "ImageTwo", 4 },
{ "ImageThree", 8 },
{ "ImageFour", 2 }
};