Results 1 to 6 of 6

Thread: Controls

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Angry

    Im not sure if this is the right forum for this but hopefully someone will know how to help. I have two things (for now) a form and a picture box. I want it so that you use the regular arrow keys to control the picture box around the form.
    Also, is there a way to have it move smooth like asteriods where it keeps going and gradually slows down (I know thats a game question but its the closest thing I could think of.) Thanx in advance.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If you set the KeyPreview property of the Form to True you can use the KeyDown event of the form and check the KeyValue.
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        `Select Case KeyCode
            Case vbKeyUp
                Picture1.Top = Picture1.Top - 30 'or whatever value you think is appropriate
            Case vbKeyDown
                Picture1.Top = Picture1.Top + 30
            Case vbKeyLeft
                Picture1.Left = Picture1.Left - 30
            Case vbKeyRight
                Picture1.Left = Picture1.Left + 30
        End Select
    End Sub
    Good luck!

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Question hmmm

    nevermind I missed the first part, Thanx it works perfect!

    [Edited by Crazy VIII on 08-21-2000 at 08:41 PM]

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    [code}
    typo error

    change
    `Select Case KeyCode
    to

    Select Case KeyCode
    [/code]


    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Yeah yeah, I'm sorry that I happend to touch the wrong key. But the code is clear enough isn't it?

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Talking

    Nah it was ok I had missed the line you wrote before the code, I had figured out the typo when it turned red, that was my mistake Thanx again!

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