How can i clear multiple text boxes when backspace is pressed?

时间:2017-08-04 12:04:39

标签: c#

Right now I am using this code which is clearing textboxes simultaneously i want to do it separately

private void metroTile13_Click(object sender, EventArgs e)
        {
            txtUser.Text = txtUser.Text.Remove(txtUser.Text.Length - 1, 1);
            txtPass.Text = txtPass.Text.Remove(txtUser.Text.Length - 1, 1);
        }

1 个答案:

答案 0 :(得分:0)

Try this:

txtUser.KeyPress += ClearTextboxes;
txtPass.KeyPress += ClearTextboxes;

private void ClearTextboxes(object sender, KeyPressEventArgs e)
{
    if (e.KeyCode == Keys.Back) 
    {
        (TextBox)sender.Text = string.Empty();
    }
}