Results 1 to 6 of 6

Thread: Using Form_KeyDown?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Using Form_KeyDown?

    I'm trying to make the arrow keys usable in a game I am writing in VB.NET
    Here's a snippet of my code:

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    If e.KeyCode = Keys.Right Then
    yy = yy - 1
    drawit()


    ....

    I can't get this to work, when I push the 'right' arrow key, the focus cycles between the form objects, moving from button to button, instead of executing this command here. How do I do this?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Using Form_KeyDown?

    You need to set the KeyPreview property of the form to true.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: Using Form_KeyDown?

    I tried this, it didn't change anything.

  4. #4
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: Using Form_KeyDown?

    Try putting e.Handled = True in there

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: Using Form_KeyDown?

    That didn't work either. The focus just keeps jumping around the buttons when I push the arrow keys.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: Using Form_KeyDown?

    Odd - it worked when I changed it to Keys.S, instead of the Arrow keys.

    I'll go with WASD. Thanks.

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