Enter Event + Shortcut

  • Thread starter Thread starter Kimochi
  • Start date Start date
K

Kimochi

Hi, i want to ask view questions
1.when i press Enter button on the textbox
how do i trigger an event?

2.How do i use shortcut key for example ctrl+s to call
certain function.
 
Hi Kimochi,

1. Capture the TextBox's KeyUp event and raise the event if the KeyCode is
Enter, something like this:

// Called from constructor
// EnterEvent += new EventHandler(EnterEventHandler);

private void textBox2_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
EnterEvent(this, EventArgs.Empty);
}
}

public event EventHandler EnterEvent;

private void EnterEventHandler(object sender, EventArgs e)
{
MessageBox.Show("You pressed the enter key in textBox2!");
}

2. You can add a menu with a menu item that has it's Shortcut property set
to CtrlS.

Joe
 
Back
Top