vb怎么判断两个移动的控件接触

来源:百度知道 编辑:UC知道 时间:2024/06/14 20:53:29
做一个打砖块的小游戏。
一个shape用timer控制来移动
另一个label用鼠标控制移动。

问:
那么怎么判断二者是否有接触啊

可以使用两个控件的left, top width, height属性的值来判断

也可以使用IntersectRect函数,这个API函数的声明如下:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function IntersectRect Lib "user32" Alias "IntersectRect" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long

使用时定义三个RECT类型变量,然后将shape和label控件的Left,Right(注意不是Width,Right=Left +Width),Top,Bottom(Bottom=Top+Height)的值赋给后两个Rect,然后传递给IntersectRect函数,如果函数返回非0值,说明二者相交,如果返回0,说明二者不相交。