shortcut keys

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

How can I add a shortcut key to a button in a windows app.?
for example
i have a button called submit and right now the only way to execute
its function is to left click the button. I would like to add a
shortcut key that correspond to this action. ctrl+s


quesitons no.2
how come when i hit the enter key in a windows control text input
field it doesn't submit? it will only submit if i click the submit
button. is there a command i missed? (I hope this makes sense)

thanks

Kuya
 
Aaron said:
How can I add a shortcut key to a button in a windows app.?
for example
i have a button called submit and right now the only way to execute
its function is to left click the button. I would like to add a
shortcut key that correspond to this action. ctrl+s

Add an event handler to key-pressing of the button, within your Form class:

private void button1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
/* If Esc key pressed, for example */
if (e.KeyChar == (char) 27)
{
MessageBox.Show("Esc pressed!!!");
}
}
 
Back
Top