vb.net - Arrow keys don't seem to work? -
i trying make maze game code can't seem work. want picture box (the player) move in direction of arrow keys. have tried code:
private sub blevel1_keydown(byval sender object, byval e system.windows.forms.keyeventargs) handles me.keydown if e.keycode = 37 pictureboxplayer.left = pictureboxplayer.left - 10 elseif e.keycode = 38 pictureboxplayer.top = pictureboxplayer.top - 10 elseif e.keycode = 39 pictureboxplayer.left = pictureboxplayer.left + 10 elseif e.keycode = 40 pictureboxplayer.top = pictureboxplayer.top + 10 end if end sub
i have tried location codes arrow keys don't seem move picture box. issue running into. ideas on how can resolve this?
the cursor keys special, used navigate focus 1 control another. intercepted before control has focus. furthermore, wrote keydown event form, won't have focus when form has other controls won't keydown event. unclear whether applies here.
the best way go intercept cursor keys yourself, before can used elsewhere. writing override form's processcmdkey() method, this:
protected overrides function processcmdkey(byref msg message, keydata keys) boolean if keydata = keys.left pictureboxplayer.left = math.max(0, pictureboxplayer.left - 10) return true elseif keydata = keys.right pictureboxplayer.left = math.min(me.clientsize.width - pictureboxplayer.width, pictureboxplayer.left + 10) return true elseif keydata = keys.up '' etc.. end if return mybase.processcmdkey(msg, keydata) end function
i threw in code prevent user moving player outside of form. finish code writing keys.up , keys.down code.
Comments
Post a Comment