so i have this form where users can drag and drop user controls(that are only picture boxes). They can't put a control on another one, as they have to place the pictures in order. Here's my current code: "TempControl" is the object that is checked in the "for each" loop "Control" is the object that just got dropped by the user
' 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
It works fine (for now), but i was wondering if there was any way to "graphically" verify the positions, like a function that checks if the form under the Control is free ?
If not, is there a more optimized algorithm for this kind of things ? What are your thoughts about it ? Thanks !
I am not sure whether I understood your question correctly, but let's see if this one helps.
Retrieves the child control at a specified location.
Example:
Dim controlAtPoint = myForm.GetChildAtPoint(anyPoint)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.