Hello Jess,
Maybe this code sample will help you:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 frm = new Form1();
frm.KeyPress += new KeyPressEventHandler(new KeyPressCode().keypressEvent);
Application.Run(frm);
}
}
public class KeyPressCode
{
public void keypressEvent(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Escape)
{
MessageBox.Show("Key ESCAPE pressed.");
}
}
}
I'm assigning a KeyPres event to the mainform at startup and check if the key ESCAPE is presed.
HTH
>Robert,
>
>I assume you are familiar with VFP's ON KEY LABEL wherein you can have a method or function and have it fired once the KEY that was assigned to do the task is pressed. The KeyPress event of a control I think is very limited. What if I want F2 function key to do something once pressed anywhere in the application? Can we do it in .NET?
>
>>Hello Jess!
>>
>>I think you should take a look at the KeyPress event (on controls). Afterwards (inside the event code) you should be able to access the pressed key by using either
e.Key or
e.Keys (don't know for sure).
>>
>>BTW: .NET usercontrols / forms do have a KeyPreview property too.
>>
>>HTH
>>
>>>Guys,
>>>
>>>Is there any equivalent command in .NET of VFP'S ON KEY LABEL something?
>>>
>>>TIA
robert.oh.