|
-
Nov 9th, 2008, 06:57 PM
#1
Thread Starter
Hyperactive Member
Align Behavior
Ok, here's the deal:
I created a custom label that moves throughout it's parent control when the user press and move the cursor on it, the application will be holding lots of this custom labels, what i want to do is if the label that is being dragged is near another label then snap the location to the label near it, so here an example of what the code should be:
Vb.net Code:
IF DraggingLabel.Left = "near" NearestLabel then
DragginLabel.Left= "Snap to nearest label left"
End If
So, if anyone could help me i'll appreciate it
-
Nov 10th, 2008, 03:05 PM
#2
Thread Starter
Hyperactive Member
-
Nov 10th, 2008, 03:33 PM
#3
Re: Align Behavior
As you're dragging the label, you need to be looping through all your other label controls and checking their Top and Left values compared to where your current Top and Left is. When they're under a certain value (like, 5 pixels) then to set your drag position = the position of the one that lined up.
It's very mathematical to do, but doable. You're going to have to play with it a bit to get it to work. This isn't an easy 3-line task. You're also going to need a boolean flag as well to know when you snapped to a position and perhaps a timer just so you can un-snap it and move it away.
-
Nov 11th, 2008, 07:59 PM
#4
Thread Starter
Hyperactive Member
Re: Align Behavior
Ok, thanks for replying:
I'm using this code for detecting if the label that is being dragged is near another label :
Vb.net Code:
If IsdraggingL.Left <= Nearlabel.left - 10 or IsdraggingL.Left >= Nearlabel.left - 10 Then
IsdragginL.left=Nearlabel.left
But that means unless the label that is being dragged is greater, or less than Nearlabel.Left the Dragginlabel.Left is going to be the same as Nearlabel.Left, but how do i find a value between the NearLabel.Left that's exactly In the Width area of the Nearlabel.Left ?
-
Nov 12th, 2008, 08:52 AM
#5
Re: Align Behavior
Code:
If IsdraggingL.Left >= Nearlabel.Left - 10 AndAlso IsdraggingL.Left <= Nearlabel.Left + 10 Then
IsdraggingL.Left = Nearlabel.Left
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|