By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,349 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

Control Position

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
are you talking about drag and drop or about resizing a form?

"Nathan Carroll" <th************@Bhutan.com> wrote in message
news:OA**************@TK2MSFTNGP11.phx.gbl...
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.

Nov 20 '05 #2

P: n/a
* "Nathan Carroll" <th************@Bhutan.com> scripsit:
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.


Do you move controls? How does a control enter space occupied by an
other control?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #3

P: n/a
"Nathan Carroll" <th************@Bhutan.com> schrieb
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?
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #4

P: n/a
button1 is dragged across screen comes into contact with a button2. I want
to prevent button1 from entering space occuped by button2.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bn*************@ID-208219.news.uni-berlin.de...
* "Nathan Carroll" <th************@Bhutan.com> scripsit:
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.


Do you move controls? How does a control enter space occupied by an
other control?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #5

P: n/a
"Nathan Carroll" <th************@Bhutan.com> schrieb
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?
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #6

P: n/a
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
Nov 20 '05 #7

P: n/a
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>
Nov 20 '05 #8

P: n/a
Exactly thanks Fergus.
"Fergus Cooney" <fi*****@post.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
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>

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.