Control Position

  • Thread starter Thread starter Nathan Carroll
  • Start date Start date
N

Nathan Carroll

I would like to know how to prevent a control from entering the space
occupied of another control. I've got my mousedown,up and move procedure
working correctly.
 
Nathan Carroll said:
I would like to know how to prevent a control from entering the
space occupied of another control. I've got my mousedown,up and move
procedure working correctly.

Sorry, I don't understand the question. How does a control "enter" the
space? What do you do in these events?
 
button1 is dragged across screen comes into contact with a button2. I want
to prevent button1 from entering space occuped by button2.
 
Nathan Carroll said:
button1 is dragged across screen comes into contact with a button2.
I want to prevent button1 from entering space occuped by button2.

Where? In the Forms designer?
 
Hi Nathan,

You'll have to check the Location of the Control that you are dragging
against the Locations of all the other Controls on the Form.

Do you have Controls within other Controls, such as inside a Panel or
TabbedPages?

Regards,
Fergus
 
Hi Nathan,

The following code was posted a while back. It does collision detection on
Controls.

To use it simply call it with a pair of Controls:

If ControlsOverlap (picBullet, picTarget) Then
MsgBox ("Target Destroyed!!")
End If

Regards,
Fergus

<code>
'--------------------------------------------------------------
'The Controls given as parameters are assumed to occupy rectangles
'as determined by .Top, .Left, .Height, and .Width properties.
'Returns True if, and only if, the rectangles occupied by the
'Controls overlap.
'
Function ControlsOverlap (c1 As Control, c2 As Control) As Boolean
Return IntervalsOverlap (c1.Top, c1.Top + c1.Height, _
c2.Top, c2.Top + c2.Height) _
And IntervalsOverlap (c1.Left, c1.Left + c1.Width, _
c2.Left, c2.Left + c2.Width)
End Function

'--------------------------------------------------------------
'An interval is a straight line. This function returns
'True if, and only if, intervals [a, b] and [x, y] intersect
'
Function IntervalsOverlap (a As Single, b As Single, _
x as Single, y As Single) As Boolean
Return WithinInterval (a, x, y) _
Or WithinInterval (b, x, y) _
Or WithinInterval (x, a, b) _
Or WithinInterval (y, a, b)
End Function

'--------------------------------------------------------------
'True if, and only if, x is within the interval [a, b]
'
Function WithinInterval (x As Single, _
a As Single, b As Single) As Boolean
Return (a <= x) And (x <= b)
End Function
</code>
 
Back
Top