作者lavendertea (go cubs!!)
看板C_Sharp
标题[问题]送出textbox内容
时间Tue Jan 13 14:55:06 2009
大家好
最近在写一个windows form小程式
希望 点击button或者按下enter都可以送出textbox内容的
button基本上没有问题
键盘判断enter我使用KeyPress事件来判断
但是只有第一次送出的textbox内容是正确的
其他只要有按下enter这个动作
就会产生 跳行+textbox内容
尝试过两个方法
1.清掉textbox内容
2.把textbox内容丢进Str[]里面 然後从Str[1]开始输出
不过跳行的问题仍然存在
以下是KeyPress事件的code 希望各位能给点意见 谢谢:)
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
String userinput = this.textBox1.Text;
if (e.KeyChar == 13)
{
if (userinput == "1")
{
MessageBox.Show("userinput:" + userinput, "message box");
this.textBox1.Text = null;
CallAdd();
CallMrec();
}
else
{
MessageBox.Show("userinput:" + userinput, "message box");
this.textBox1.Text = null;
}
}
}
--
Rock N' Roll Ain't Noise Pollution
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.221.67.235
1F:→ lavendertea:补充一下 第一次如果输入不为1 之後输入1跳行判断错 01/13 15:07
2F:→ lavendertea:如果之後又输入几次1 会突然又不跳行&判断正确 01/13 15:08
3F:推 zhadow:加上 e.Handled = true; 让 textBox1 收不到 enter键即可 01/14 03:55
4F:→ lavendertea:感谢~这方法行得通:) 01/14 09:36