VB.NET确定一个控件是否与另一个控件共享空间

VB.NET确定一个控件是否与另一个控件共享空间,vb.net,Vb.net,我有一个表单,我可以用鼠标移动标签。我想做的是确保我不会将一个标签移动到另一个控件使用的空间中 有没有比我下面使用的更好、更有效的方法: for each c as control in me.controls if c.location.x > testcontrol.location.x and c.location.x < testcontrol.location.x + testcontrol.height and c.location.y > testcontro

我有一个表单,我可以用鼠标移动标签。我想做的是确保我不会将一个标签移动到另一个控件使用的空间中

有没有比我下面使用的更好、更有效的方法:

for each c as control in me.controls
  if c.location.x > testcontrol.location.x and c.location.x < testcontrol.location.x + testcontrol.height and c.location.y > testcontrol.location.y and c.location.y < testcontrol.location.y + testcontrol.width then
     'testcontrol shares space with control c
     <do stuff>
   End if
next
me.controls中每个c控件的

如果c.location.x>testcontrol.location.x和c.location.xtestcontrol.location.y和c.location.y
我发现上面的内容过于笨拙,难以理解/阅读。只是希望有一些VB的魔术在那里,将做这更有效

从我的搜索中,我看到C#有一个“intersectswith”函数,但我似乎找不到类似的VB函数。这显示vb使用intersectwith,但我无法让它为我的东西工作。可能是不同版本的VB?

您忘记添加:

对于Me.Controls中的每个c作为控件
如果c.Bounds.IntersectsWith(testcontrol.Bounds),则
'testcontrol与控件c共享空间
如果结束
下一个

不是一种方法,而是一种方法。

D'oh。我责备今天是星期一。现在谢谢你。很乐意帮忙。顺便说一句,今天是星期二;-)。仅供参考:在加拿大,这是一个巧妙地伪装成星期二的星期一(对我们来说是一个漫长的周末)。
For Each c As Control In Me.Controls
    If c.Bounds.IntersectsWith(testcontrol.Bounds) Then
         'testcontrol shares space with control c
        <do stuff>
    End If
Next