Click here to Skip to main content
15,904,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I wrote this method for control keys .

How to be sent to parameter this method?

**************************************************************
MIDL
Public void KeyContoroler(KeyEventArgs e)
{
if(e.keychar==keys.Enter)
{
    messagebox.show("Enter Pressed");
}

if (e.keychar==keys.escape)
{
    messagebox.show("Escape Pressed");
}
}


**************************************************************

It's very important for me.

Please help me.
Posted
Updated 30-Jul-10 23:02pm
v3
Comments
Sandeep Mewara 31-Jul-10 4:04am    
What do you mean by: "How to be sent to parameter this method?"

1 solution

Just writing a method will do nothing, you have to hook it to the event, and supply it as an acceptable eventhandler - which mean two parameters, "object sender" and "KeyEventArgs e" - not one.

Two ways to do it.
1) In the form designer, highlight the control you want to handle the even, and select Events on the Properties window - it's the little button with a lightning bolt on it. Double click the KeyPress event and a handler will be generated and a minimal method supplied.
2) In the code viewer, probably in the FormLoad event, add a handler by typing your control name followed by ".KeyPress", then "+=" followed by the Tab key twice. This will create the same method as above and hook it into the event.
 
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