سؤال

I'm currently trying to make a simple comparing program but I'm stuck at the moment. I was wondering if it is possible to assign a value to an image namely 4 picture boxes, then comparing the values to see which box has a higher value. I'm fairly new to programming so I would really appreciate some examples.

here is an example of what im trying to achieve. enter image description here

1: Click two classes to compare

2: Then a message box appears showing which class has a higher value.

هل كانت مفيدة؟

المحلول

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 }
};
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top