Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a vb program, a form with a picturebox, I want on mouse left click to change the image and set another one, I want to use an if then statement so ir will change picture according to the pic in use. My problem I get an error "operator '=' is not defined for types 'system.drawing.image'...", how can I change the code to work?

VB
If e.Button = Windows.Forms.MouseButtons.Left Then
       If PictureBox1.Image = My.Resources._1 Then
        PictureBox1.Image = My.Resources._2
    End If
End If
Posted
Comments
Rddezh 26-Dec-12 12:57pm    
Hi! You should check the data type of My.Resources._2.

1. Insert brakepoint in the line, where seting value to picturebox image
2. Debug the program
3. Put mouse over the My.Resources._2 and check if it is the Image, Bitmap or any other type, that can be directly converted to Image.

I never used VB too much, but I'm familiar with c# ;)
Member 3892343 26-Dec-12 13:16pm    
the error is being in the "if pocturebox1.image = my.recources._1" and it is in design time and I cannot debug, it is not in the change image "picturebox1.image = my.recources._2", I found some code "if referenceequals(picturebox1.image,my.recources._1) = true" it does not have an error but not working at runtime, any help, C# is similar to vb.

1 solution

Have you tried the equals method from Image ObjecT?

VB
If PictureBox1.Image.Equals(My.Resources._1) Then
    'Do your stuff
End If


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900