subanki subanki - 6 months ago 21
Vb.net Question

Unable to use = operator in a "If" statement

Why can't I use = operator over here. Anyway to solve this problem ?

If PictureBox1.Image = My.Resources.pic001 Then
x = 1
Else
x = 0
End If


The error message is:


Operator '=' is not defined for types
'System.Drawing.Image' and
'System.Drawing.Bitmap'

Answer

Assuming that PictureBox1.Image references the same Image object as My.Resources.pic001, then you could use:

If Object.ReferenceEquals(PictureBox1.Image, My.Resources.pic001) Then