文本框未清除
我输入的时间为3,所有其他值为。不保存,我必须将时间更改为2,其他文本框值应清除
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Saved Successfully");
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox1.Text = "";
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox1.Text = "";
}
}
}
答案 0 :(得分:1)
我创建了此函数以清空当前表单中的所有文本框:
public void ClearTextBoxes()
{
foreach (Control x in this.Controls)
{
if (x is TextBox)
{
((TextBox)x).Text = String.Empty;
}
}
}