在 vb.net 中以图形方式检测窗体上的控件

Graphically detect a control on a form in vb.net

所以我有这个表单,用户可以在其中拖放用户控件(只是图片框)。他们不能对另一个进行控制,因为他们必须按顺序放置图片。这是我当前的代码: "TempControl" 是在 "for each" 循环中检查的对象 "Control" 是刚刚被用户删除的对象

        ' vertical check: there's two lines possible
            If Control.Top < 200 Then
                Control.Top = 70
            Else
                Control.Top = 240
            End If
        ' horizontal check:
        For Each tempControl As MyUSerControl In MyArray
                If tempControl.Left < Control.Left And tempControl.Left + tempControl.Width > Control.Left Then    'If the left limit of the moved object is in the fix object                   
                        Control.Left = tempControl.Left + tempControl.Width + 5    'Put it on the fix object's right side
                End If

                If tempControl.Left > Control.Left And tempControl.Left < Control.Left + Control.Width Then  'If the right limit of the moved object is in the fix object        
                        Control.Left = tempControl.Left - Control.Width - 5    'Put it on the left side
                End If
        Next

它工作正常(目前),但我想知道是否有任何方法可以 "graphically" 验证位置,例如检查控件下的表单是否空闲的函数?

如果没有,有没有更优化的算法来处理这种事情?你对此有何看法? 谢谢!

我不确定我是否正确理解了你的问题,但让我们看看这个问题是否有帮助。

GetChildAtPoint(Point)

Retrieves the child control at a specified location.

示例:

Dim controlAtPoint = myForm.GetChildAtPoint(anyPoint)