0

I know how to check if two PictureBox have same Image and it works:

If PictureBox1.Image Is PictureBox2.Image Then   
**What I want it to do**
End If

I tried do it with three PictureBox but not working:

If (PictureBox1.Image Is PictureBox2.Image) And (PictureBox1.Image Is PictureBox3.Image) Then
MessageBox.Show("TEST")
End If

If someone could help me, I would be grateful. Thanks.

Teemu
  • 9
  • 1
  • That depends on how you load the image. If you use the `PictureBox.ImageLocation` property you can just verify that... But if you dynamically load images you have to compare them pixel by pixel. – Visual Vincent May 21 '16 at 10:42
  • Okey. I used PictureBox1.Image = Image.FromFile("*source here*") But how to compare if I use PictureBox.ImageLocation? Sry for stupid question. I'm new with Visual Basic. – Teemu May 21 '16 at 11:11
  • 1
    Use `PictureBox1.ImageLocation = "source here"`, then just compare the `ImageLocation` properties. `If PictureBox1.ImageLocation = PictureBox2.ImageLocation Then` --- This will only work if you always use the `ImageLocation` property, – Visual Vincent May 21 '16 at 13:22
  • Thank you so much! :) Now it works: If (PictureBox1.ImageLocation = PictureBox2.ImageLocation) And (PictureBox1.ImageLocation = PictureBox3.ImageLocation) Then – Teemu May 21 '16 at 13:58
  • No problem! But you should use `AndAlso` instead of `And`. It's faster. – Visual Vincent May 21 '16 at 14:20
  • 1
    http://www.panopticoncentral.net/2003/08/18/the-ballad-of-andalso-and-orelse/, http://stackoverflow.com/questions/302047/what-is-the-difference-between-and-and-andalso-in-vb-net – RoyalPotato May 21 '16 at 20:21
  • 1
    ..Because AndAlso doesn't evaluate your second expression if the first one is false. – Kake_Fisk May 21 '16 at 22:37
  • @Kake_Fisk : Yep. Was in a hurry while writing so I didn't have the time to include an explanation. :) – Visual Vincent May 21 '16 at 23:09

1 Answers1

-1

You can't do that in VB.net, you need to do something like:

If picturebox1.Image Is picturebox2.Image And picturebox1.Image Is picturebox3.Image Then
  '**What you want to do**
End if
LarsTech
  • 80,625
  • 14
  • 153
  • 225