Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void MDIParent1_KeyDown(object s, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode.ToString() == "q")
            {
                MessageBox.Show("welcome");
                this.KeyPreview = false;
            }
        }

when i press ctrl+q, message box should show., i used above coding but its not working
Posted
Updated 17-Sep-12 19:05pm
v2

1 solution

Set the keyPreview property to true
and code should be
C#
e.KeyCode.ToString() == "Q"
 
Share this answer
 
Comments
Umapathi K 18-Sep-12 1:25am    
not working
Umapathi K 18-Sep-12 1:30am    
i tried with alt+1q also., but not working

private void MDIParent1_KeyDown(object s, KeyEventArgs e)
{
if (e.Alt && e.KeyCode.ToString() == "Q")
{
this.KeyPreview = true;
MessageBox.Show("ad");
}
}
Menon Santosh 18-Sep-12 1:32am    
i have tested this code on my pc and it is working fine,follow these steps
1) Set the keypreview property of the form true
2) implement the above code in your form
3) run your project and press CTRL + Q on your form
and if still it is not working then check your keyboard's CTRL and Q key

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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