C#: Windows Forms: Getting keystrokes in a panel/picturebox?
- by Rosarch
I'm making a level editor for a game using windows forms. The form has several drop down menus, text boxes, etc, where the user can type information.
I want to make commands like CTRL + V or CTRL + A available for working within the game world itself, not text manipulation. The game world is represented by a PictureBox contained in a Panel.
This event handler isn't ever firing:
private System.Windows.Forms.Panel canvas;
// ...
this.canvas = new System.Windows.Forms.Panel();
// ...
this.canvas.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.canvas_PreviewKeyDown);
What is the preferred way of doing this? Can a panel even receive keyboard input? I would like to allow the user to use copy/paste/select-all commands when working with the text input, but not when placing objects in the game world.