以图形方式检测vb.net中表单上的控件

问题描述 投票:0回答:1

所以我有这个表单,用户可以拖放用户控件(只是图片框)。他们无法控制另一个,因为他们必须按顺序放置图片。这是我当前的代码:“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

它工作正常(现在),但我想知道是否有任何方式“图形”验证位置,如一个功能,检查控件下的表格是否是免费的?

如果没有,是否有更优化的算法用于此类事情?你对此有何看法?谢谢 !

vb.net user-interface controls
1个回答
0
投票

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

GetChildAtPoint(Point)

检索指定位置的子控件。

例:

Dim controlAtPoint = myForm.GetChildAtPoint(anyPoint)
© www.soinside.com 2019 - 2024. All rights reserved.