Testing for image over image
Hiya peeps,
I wonder if you can help,
I have a number of images placed on a form by drag and dropping them. They are repositioned by snaping to a certain area , and as long as you move them within this designated area, everything is fine. :)
However when rushing I can click on the image and it will snap to the designated area, but may go over or under an existing image.
As the images are selectively counted, it can cause problems by counting extra items placed on top of others.:eek:
Is there a way of detecting an image on top of another? :confused:
:wave:
Re: Testing for image over image
I thought of checking the .top of every imageholder, but am not sure if this is the way to go? it seems like a lot of looping :(
Re: Testing for image over image
vb Code:
Private Function Overlapped(pObj1 As Object, pObj2 As Object) As Boolean
If ((pObj1.Top + pObj1.Height >= pObj2.Top And _
pObj1.Top <= (pObj2.Top + pObj2.Height)) And _
(pObj1.Left <= pObj2.Left + pObj2.Width And _
pObj1.Left + pObj1.Width >= pObj2.Left)) Then
Overlapped = True
End If
End Function
Then you can use it like this
vb Code:
If Overlapped(Image1, Image2) Then
'Overlap, do Something here
End If
Re: Testing for image over image
Great thanks, but it's still a case of taking each image in turn and testing it against all the others, every time I move one, isn't it?