单击后仅删除文本框默认文本,c# form
delete textbox default text only after one click, c# form
我希望在我的 Textbox
中只删除一次我的文本,这样它就不会在我每次单击时都被清除 Textbox
。我当前的代码如下:
private void textBox1_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
但是我怎样才能让它只删除一次文本?
您可以使用一个简单的布尔标志:
public partial class Form1 : Form
{
bool firstClick = true;
并且在您的事件处理程序中:
private void textBox1_Click(object sender, EventArgs e)
{
if (firstClick)
{
textBox1.Text = string.Empty;
firstClick = false;
}
}
我希望在我的 Textbox
中只删除一次我的文本,这样它就不会在我每次单击时都被清除 Textbox
。我当前的代码如下:
private void textBox1_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
但是我怎样才能让它只删除一次文本?
您可以使用一个简单的布尔标志:
public partial class Form1 : Form
{
bool firstClick = true;
并且在您的事件处理程序中:
private void textBox1_Click(object sender, EventArgs e)
{
if (firstClick)
{
textBox1.Text = string.Empty;
firstClick = false;
}
}