Reputation: 267
How can I move a control ( a image ) in the form by keyboard? I don't know how to do it. C# Thanks
Upvotes: 0
Views: 966
Reputation: 4652
If you mean moving objects in design mode, it's impossible, because positioning of elements on form should be done via CSS.
Upvotes: 0
Reputation: 23113
Assuming you use WinForm (but for WPF its not much different):
Each control has a KeyDown
event, which is fired when a key is pressed down (and a KeyUP and KeyPress which are fired accordingly:
So you can do something like the following (e.g. in the constructor or load event of the form):
//this enables the form to receive all key events if a child control has focus
this.KeyPreview = true;
this.KeyDown += (s, e) =>
{
if(e.KeyCode == Keys.Up)
picture.Location.Y++;
//etc...
}
Upvotes: 2