Re: [02/03] Drag and drop.
I'm not exactly sure what you are asking, but I will hazzard a guess. You want to be able to move labels around on the form, but they can't overlap other labels?
First, the mouse move event you have, you can use for all the labels, add all the labels to the mousemove to this event. Then in the procedureinstead of using label1 use sender. Sender is the label that is beign moved.
Example
VB Code:
'used a click event for demonstration
Private Sub Labels_Click(sender as Object, e as EventArgs) Handles Label1.Click, Label2.Click, Label3.Click
Messagebox.Show(DirectCast(sender, Label).Text)
End Sub
Then to make sure the label isn't going to overlap another label, you may want to wait for the mouseup event after the mousemove. It may be too much work to do in the move. I would say create an array of all your labels that you are going to compare it to, every time you move a label you will have to update the array. Then it would be a matter of looping through the array.
VB Code:
Private Function SenderIsOverlaping(lbl As Label) As Boolean 'lbl is the moving label
'the array of labels is called ArrayLabels, and we will assume it is populated corectly
For l as Label in ArrayLabels
'loop through the array checking if the moving label overlaps anyother
Next
End Function
Hope this helps.
Re: [02/03] Drag and drop.
Quote:
Originally Posted by mpdeglau
I'm not exactly sure what you are asking, but I will hazzard a guess. You want to be able to move labels around on the form, but they can't overlap other labels?
First, the mouse move event you have, you can use for all the labels, add all the labels to the mousemove to this event. Then in the procedureinstead of using label1 use sender. Sender is the label that is beign moved.
Example
VB Code:
'used a click event for demonstration
Private Sub Labels_Click(sender as Object, e as EventArgs) Handles Label1.Click, Label2.Click, Label3.Click
Messagebox.Show(DirectCast(sender, Label).Text)
End Sub
Then to make sure the label isn't going to overlap another label, you may want to wait for the mouseup event after the mousemove. It may be too much work to do in the move. I would say create an array of all your labels that you are going to compare it to, every time you move a label you will have to update the array. Then it would be a matter of looping through the array.
VB Code:
Private Function SenderIsOverlaping(lbl As Label) As Boolean 'lbl is the moving label
'the array of labels is called ArrayLabels, and we will assume it is populated corectly
For l as Label in ArrayLabels
'loop through the array checking if the moving label overlaps anyother
Next
End Function
Hope this helps.
Hi mpdeglau,
Thanks for your reply, I'll check it later!
Wkr,
sparrow1