所以我有这个表单,用户可以在其中拖放用户控件(仅是图片框(。他们不能在另一个控件上放置控件,因为他们必须按顺序放置图片。这是我当前的代码:"TempControl"是在"for each"循环中选中的对象"控件"是用户刚刚丢弃的对象
' 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
它工作正常(目前(,但我想知道是否有任何方法可以"图形化"验证位置,例如检查控件下的表单是否免费的函数?
如果没有,有没有针对这种事情的更优化的算法?你对此有何看法?谢谢!
我不确定我是否正确理解了你的问题,但让我们看看这个是否有帮助。
GetChildAtPoint(Point(
检索指定位置的子控件。
例:
Dim controlAtPoint = myForm.GetChildAtPoint(anyPoint)