Results 1 to 5 of 5

Thread: Align Behavior

  1. #1

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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:
    1. IF DraggingLabel.Left = "near" NearestLabel then
    2.      DragginLabel.Left= "Snap to nearest label left"
    3. End If

    So, if anyone could help me i'll appreciate it
    C# and WPF developer
    My Website:
    http://singlebits.com/

  2. #2

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: Align Behavior

    Can anyone help me ?
    C# and WPF developer
    My Website:
    http://singlebits.com/

  3. #3
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  4. #4

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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:
    1. If IsdraggingL.Left <= Nearlabel.left - 10 or IsdraggingL.Left >= Nearlabel.left - 10 Then
    2. 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 ?
    C# and WPF developer
    My Website:
    http://singlebits.com/

  5. #5
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Align Behavior

    Code:
    If IsdraggingL.Left >= Nearlabel.Left - 10 AndAlso IsdraggingL.Left <= Nearlabel.Left + 10 Then
    IsdraggingL.Left = Nearlabel.Left
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width