Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect enter key pressed in textbox

Status
Not open for further replies.

hh2424

Programmer
Feb 18, 2003
37
US
I'm sure some people may have asked this question before but I couldn't quickly find this.

But how can I detect an enter key was pressed in a text box?

thanks,
 
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnKeyPress);
//Put this in InitializeComponent

protected void OnKeyPress(object sender,KeyPressEventArgs e)
{
if (e.KeyChar == 13) //This allows for detection of all catchable keys ( to my knowledge )
{
//Cool key stuff here
}
}

Regards,
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top