Compare Images on double click event

Carlo Goretti 121 Reputation points
2020-08-21T10:19:33.28+00:00

Hey!

Im trying to compare two images with each other but dont get it to work..
I have dynamic pictureboxes..
and want to make that if you double click one. Then it changes picture..
But i want to make that only one of them can have that picture..

Image test = Resources.Favorit;
            for(int i = 0; i < lstPictureBox.Count(); i++)
            {
                if(lstPictureBox[i].Image == test)
                {
                    lstPictureBox[i].Image = Resources.FavoritVit;
                }
            }
            PictureBox oPictureBox = (PictureBox)sender;
            oPictureBox.Image = Resources.Favorit;

any ideas?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,903 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2020-08-21T18:48:16.53+00:00

    Check an alternative too. If Tag is not yet used for other purposes, then try something like this:

    Image test = Resources.Favorit;
    for(int i = 0; i < lstPictureBox.Count(); i++)
    {
    > if( (string)lstPictureBox[i].Tag == “Favorit”)
    > {
    > lstPictureBox[i].Image = Resources.FavoritVit;
    > lstPictureBox[i].Tag == “FavoritVit”;
    > }
    }
    PictureBox oPictureBox = (PictureBox)sender;
    oPictureBox.Image = Resources.Favorit;
    oPictureBox.Tag = “Favorit”;

    But, maybe the next code works too:

    for(int i = 0; i < lstPictureBox.Count(); i++)
    {
    > lstPictureBox[i].Image = Resources.FavoritVit;
    }
    PictureBox oPictureBox = (PictureBox)sender;
    oPictureBox.Image = Resources.Favorit;

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.