Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Ankur\m/ 22-Jul-13 9:32am    
Do you mean when you hit 'Y' key on the keyboard, all the checkboxes in your page should get checked?

1 solution

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

C#
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;
            }
        }
    }


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900