Click here to Skip to main content
11,431,011 members (72,295 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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?

        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 26-Dec-12 7:38am
Rddezh at 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 at 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have you tried the equals method from Image ObjecT?

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

Hope this helps.

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

Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100