winforms - Key press events in C# -- Moving a PictureBox -
i attempting move picturebox(picuser) , down via key press events. newer c# , able via vb. such confused problem following code:
private void picuser_keydown(object sender, system.windows.forms.keyeventargs e) { if (e.keycode == keys.w) { picuser.top -= 10; } }
there no "error" code, picturebox doesn't move.
a picturebox
has no keydown
event. has previewkeydown
instead , requires picturebox
have focus.
i suggest use keydown
of form
host picturebox
instead , use same exact code:
public form1() { initializecomponent(); this.keydown += new system.windows.forms.keyeventhandler(this.form1_keydown); } private void form1_keydown(object sender, keyeventargs e) { if (e.keycode == keys.w) { picuser.top -= 10; } }
Comments
Post a Comment