如何判断一个控件是否在选中的区域中?(50分)

  • 主题发起人 主题发起人 jieson
  • 开始时间 开始时间
J

jieson

Unregistered / Unconfirmed
GUEST, unregistred user!
我画了一个矩形框,我要判断一下界面上的哪些控件都被我这个框选中了,有api吗?
 
没有吧,还得用土办法.认坐标.
 
通过坐标来判断不就可以了吗<br>判断鼠标是否在控件的坐标区域内
 
看来只能判断了,想偷个懒,有没有现成的算法啊,嘿嘿,谢谢啦!<br><br>二楼,判断鼠标好象不行吧,画区域的时候鼠标不一定经过的
 
判断控件在屏幕的坐标.
 
那现在问题就转换成了判断两个区域是否重叠了,看来是没api了,哪位有写过函数吗?
 
判断坐标怎么判断啊,选那个点呢?难道得上下左右四条边那么比较吗?我晕哦!
 
:)<br>VB有写过,Delphi就没有.现在也不用VB了.
 
用最笨的办法写了一个,汗!<br>function GetRectIsOverlap(Rect1,Rect2:TRect):boolean;<br> &nbsp;begin<br> &nbsp; &nbsp;result := false;<br><br> &nbsp; &nbsp;if Rect2.Left &gt; Rect1.Left then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if Rect2.Left &lt; Rect1.Right then<br> &nbsp; &nbsp; &nbsp; &nbsp;if Rect2.Top &gt; Rect1.Top then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Rect2.Top &lt; Rect1.Bottom then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := true<br> &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Rect2.Bottom &gt; Rect1.Top then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := true;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if Rect1.Left &lt; Rect2.Right then<br> &nbsp; &nbsp; &nbsp; &nbsp;if Rect2.Top &gt; Rect1.Top then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Rect2.Top &lt; Rect1.Bottom then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := true<br> &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Rect2.Bottom &gt; Rect1.Top then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := true;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end;
 
挺好,有的时候写程序就得这么笨.
 
多人接受答案了。
 
后退
顶部