访问复选框键盘按键 [英] access checkbox keybord key press

查看:96
本文介绍了访问复选框键盘按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i想要访问复选框时键盘按键就像我点击'Y'然后勾选复选框就可以重播

谢谢提前

hi
i want to access check box when keyboard key press like i click 'Y' then check box are checked it is possible please replay
thank to advance

推荐答案

我不明白这个的目的。但是,有可能这样做。



请按照步骤,



步骤1)

您需要在表单级别处理Keypress事件。见下面的代码



I don't understand the purpose of this. However, it is possible to do so.

Please follow the steps,

Step 1)
You will need to handle the Keypress event in form level. See below code

public partial class Form1 : Form
    {

        private bool YKeyEntered = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (YKeyEntered)
            {
                chkInternal.Checked = true;
            }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Y)
            {
                YKeyEntered = true;
            }
        }
    }





第2步

默认情况下,表单无法读取密钥。将表单的KeyPreview属性设置为true,以便表单在到达表单上的任何控件之前接收键盘消息。



在此代码,如果在表单处于活动状态时按下键'Y',则会检查名为'chkInternal'的chechbox。



请通过这些链接,

http://msdn.microsoft.com/en-us/library/ms171538.aspx [ ^ ]



http: //msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx [ ^ ]





如果此解决方案可以帮助您标记为已解决。如果您对此仍有疑问,请与我们联系。



Step 2
By default Form cannot read a key. Set the 'KeyPreview' property of the form to 'true', so that keyboard messages are received by the form before they reach any controls on the form.

In this code, If the Key 'Y' is pressed when the form is active, the chechbox named 'chkInternal' get checked.

Please go through these links,
http://msdn.microsoft.com/en-us/library/ms171538.aspx[^]

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx[^]


If this solutions helps you please mark as solved. Let me know if you still got questions regarding this.


这篇关于访问复选框键盘按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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