I want to register when the key “Tab” has been pressed, but can’t figure out how to use the ProcessDialogKey.
This is what i got:
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Keypress);
private void Keypress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("button: " + e.KeyChar);
}
This can only capture regular chars, but i also need other like “Tab” etc….
So i studied a bit, and found that many had used the ProcessDialogKey, but i’m abit uncertain how to use it.
here’s what i got:
protected override bool ProcessDialogKey(Keys keyData)
{
switch (keyData)
{
case Keys.Up:
MessageBox.Show("Up");
break;
case Keys.Tab:
MessageBox.Show("Tab");
break;
default:
break;
}
}
I get the error: 'project.frm_test.ProcessDialogKey(System.Windows.Forms.Keys)': no suitable method found to override
What am i doing wrong?
And bear with me… i’m used to php 🙂
So i’m kinda new to c# 🙂
Your code is working, you message box is just displaying the tab character i.e. blank space.
Cast to int and you will see it’s working:
EDIT:
Otherwise look at this code: