How to use If Statment to check which Picturebox image is shown

Hashim Idrees 21 Reputation points
2021-02-16T12:06:40.807+00:00

Hay i have a many picture boxes in a form. and i want to change one picture box image on bases of other picture box image.

For example using if statement, I want to change picturebox1 image[picture1] when picturebox2 image[picture5].

           if (pictureBoxDED3.Image == SCADA.Properties.Resources.Breaker_Open)
            {
                pictureBoxSectionD3.Image = SCADA.Properties.Resources.Dead_voltage_section;
            }
          

this doest show error but nor works.
please help me solve it. i am a beginner.
thanks

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

2 answers

Sort by: Most helpful
  1. Castorix31 79,911 Reputation points
    2021-02-16T12:44:32.893+00:00

    The resource name is not stored in the PictureBox

    A way is to use the Tag property, that you set with the name of the resource when you assign the image to the PictureBox
    Then you will be able to test pictureBoxDED3.Tag

    0 comments No comments

  2. Viorel 106.4K Reputation points
    2021-02-16T13:02:29.167+00:00

    I think that it will work if you define some members (maybe static) like this:

    static readonly Image Breaker_Open = SCADA.Properties.Resources.Breaker_Open;
    
    private void SomeFunction( )
    {
       if( pictureBoxDED3.Image == Breaker_Open )
       {
             . . .
    
    0 comments No comments