Moving Buttons on panel, not overlay

Hello

I want to move several buttons on a panel. Thats working correctly.
But while moving I want to check if on the new place, there is alreasy a button.
I am using Mousemove, so it should check at every mousemove event, if the button I want to move will be on the top of another button...

How can I do that?

Thanks

Sven
RuttensoftAsked:
Who is Participating?
 
dctuckConnect With a Mentor Commented:
This should work:

        For Each myControl As Control In Me.Controls
            If TypeOf (myControl) Is Button Then
                If Button1.Bounds.IntersectsWith(myControl.Bounds) Then
                    ......
                End If
            End If
        Next
0
 
dctuckCommented:
If you are moving Button1, and want to check if it is over Button2, you could use:

If Button1.ClientRectangle.IntersectsWith(Button2.ClientRectangle) Then
....
End If

This checks the whole of the Button1 rectangle to see if any point in it overlaps Button2's area
0
 
RuttensoftAuthor Commented:
Thanks.
I will have 40 controls, 20 buttons and 20 picturebox. Is it possible to check for all other 39 controls very fast?
0
 
dctuckCommented:
Sorry - change ClientRectangle to Bounds, so:

If Button1.Bounds.IntersectsWith(Button2.Bounds) Then
....
End If

My mistake...
0
 
RuttensoftAuthor Commented:
thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.