我希望我的Textbox
只删除一次我的文字,这样每次点击都不会清除Textbox
。我目前的代码如下:
private void textBox1_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
但是我怎么能让它只删除一次文本?
答案 0 :(得分:4)
你可以使用一个简单的布尔标志:
public partial class Form1 : Form
{
bool firstClick = true;
在您的事件处理程序中:
private void textBox1_Click(object sender, EventArgs e)
{
if (firstClick)
{
textBox1.Text = string.Empty;
firstClick = false;
}
}