C#:Windows窗体:让按键在面板/图片框? [英] C#: Windows Forms: Getting keystrokes in a panel/picturebox?

查看:131
本文介绍了C#:Windows窗体:让按键在面板/图片框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个游戏使用Windows窗体一个关卡编辑器。的形式有几个下拉菜单,文本框等,用户可以在其中输入信息

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.

我想为游戏世界本身的工作就像 CTRL + V Ctrl + A 可用命令,而不是文本操作。游戏的世界是psented再$ P $一个图片框包含在面板

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);

什么是$ P $这样做的pferred方式?可以在面板即使接收键盘输入?在游戏世界中的配售对象的时候,我想允许用户与文本输入操作时使用的复制/粘贴/全选命令,但不是。

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.

推荐答案

您可能会想这样做的关键捕获在表单级别。这是强烈建议从谁帮写底层的.NET code的人阅读:

You'll probably want to do the key capture at the form level. This is highly recommended reading from the person who helped write the underlying .NET code:

http://blogs.msdn.com/jfoscoding/存档/ 2005/01/24 / 359334.aspx

这篇关于C#:Windows窗体:让按键在面板/图片框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆