moving an object using the arrow keys

am I just being increadbly dense?

Page 1 of 1

4 Replies - 5269 Views - Last Post: 02 March 2010 - 07:41 PM Rate Topic: -----

#1 theblackmage  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 21-January 10

moving an object using the arrow keys

Posted 01 March 2010 - 06:06 AM

well, howdy y'all

so yeah, I've done a search of the tutorials, and even of the search function, and I coouldn't find anything on this topic. I'm stuck trying to get my object too move with the arrow keys, so I'm asking here.

please can someone direct me to a topic too help/post it here. I have the code so it reacts too the keys, i just need to know how to actualy make it move

thanks for any help and replies

:basecase: - me
:withstupid:

Is This A Good Question/Topic? 0
  • +

Replies To: moving an object using the arrow keys

#2 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: moving an object using the arrow keys

Posted 01 March 2010 - 08:03 AM

For starters could you show the code that you have attempted so far? That is a good starting point to offer help so we don't tell you to redo the steps you have already done. And please :code: when you post it.
Was This Post Helpful? 0
  • +
  • -

#3 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 782
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: moving an object using the arrow keys

Posted 01 March 2010 - 09:13 AM

If you want to move something on the form, then you need to work with the Location property, assigning a new point for each arrow key press (increment/decrement the X value when left/right keys are pressed and the Y value for up/down keys).
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Hugo*


Reputation:

Re: moving an object using the arrow keys

Posted 02 March 2010 - 06:33 PM


Show us some code, we arent mind readers...you have to put forth some effort.
-Keystrokes-

I have come across this same problem, unfortunatly i couldnt solve it,
so i make some minor changes and now these keys work fine:
A=Left
W=Up
D=Right
S=Down
If you havnt forgot youve posted this, email me if you want the code
at: [email protected]
Thanks
(did i help you? if so...press the +)

Was This Post Helpful? 0

#5 finaiized  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 29-November 09

Re: moving an object using the arrow keys

Posted 02 March 2010 - 07:41 PM

Since the above probably weren't too helpful to you, I have created a fully working example for you: Here it is. I think the thing you missed is probably Invalidate()- Windows Forms draws through GDI+, which draws once unless you tell it to. We use DoubleBuffered() to prevent flashing (try removing it!). Remember to replace the line where I load the image with your own.

This post has been edited by finaiized: 02 March 2010 - 07:43 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1