在C#回车键preSS [英] Enter key press in C#
本文介绍了在C#回车键preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToInt32(e.KeyChar) == 13)
{
MessageBox.Show("Enter pressed");
}
}
和这样的:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter))
{
MessageBox.Show(" Enter pressed ");
}
}
和这样的:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Keys.Enter)
{
MessageBox.Show(" Enter pressed ");
}
}
但他们没有工作......
but they're not working...
在我写的东西和preSS <大骨节病>输入骨节病>,这是行不通的。这既突出我的文字。
When I write something and press Enter, it does not work. It only highlights my text.
推荐答案
试试这个code,可能会工作(假设Windows窗体):
Try this code,might work (Assuming windows form):
private void CheckEnter(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
// Enter key pressed
}
}
注册的事件是这样的:
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnter);
这篇关于在C#回车键preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文