c# textbox 按下回车清除文本内容

2025-02-26 05:10:30
推荐回答(3个)
回答1:

这是因为你在KeyDown事件结束以后,系统还会给一个Enter回车字符给Textbox1,所以一直都会在第二行,你改成下面这样就行了
if (e.KeyCode == Keys.Enter)
{
this.textBox1.Text = "";
e.Handled = true;
}

回答2:

在KeyUp事件进行处理!

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
            if (e.KeyCode == Keys.Enter)
            {
                this.textBox1.Text = "";
            }
 }

如果是多行文本KeyDown的话,肯定会向文本框加入换行的!

回答3:

boolean tag = true;
configure:3527: error: in `/Users/niko/memcachedbuild/libevent-1.4.14-stable':
configure:3531: error: C compiler cannot create executables
See `config.log' for more details.