Results 1 to 4 of 4

Thread: snap to grid

  1. #1

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222
    Anyone know of any API or any way of easily coding a 'snap to grid' feature?

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I wrote a maze designer for a game, and it does it.
    Take what you need.

    http://members.fortunecity.com/plend...20Designer.zip
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    just in case you dont want to find the stuff for yourself ;

    Code:
    Private Const SnapValue As Long = 20
    Private MouseX As Single
    Private MouseY As Single
    
    Private Sub pictureBox1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseX = RoundTo(SnapValue, X)
        MouseY = RoundTo(SnapValue, Y)
        pictureBox1.Cls
        pictureBox1.Circle (MouseX - 1, MouseY - 1), 2, vbRed
    End Sub
    
    Private Function RoundTo(NumberToRoundTo As Long, NumberToRound) As Long
        If (NumberToRound < NumberToRoundTo) Then
            If (NumberToRound < (NumberToRoundTo / 2)) Then
                RoundTo = 0
            Else
                RoundTo = NumberToRoundTo
            End If
        Else
            For i = 2 To NumberToRound
                If (NumberToRound < (NumberToRoundTo * i)) Then
                    If (NumberToRound < ((i * NumberToRoundTo) - (NumberToRoundTo / 2))) Then
                        RoundTo = (i * NumberToRoundTo) - NumberToRoundTo
                        Exit For
                    ElseIf (NumberToRound > ((i * NumberToRoundTo) - (NumberToRoundTo / 2))) Then
                        RoundTo = (i * NumberToRoundTo)
                        Exit For
                    End If
                End If
            Next i
        End If
    End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222
    Thank you - that is perfect

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