恢复文本框C#的上一个条目

Dar*_*ght 1 .net c# validation

我正在验证如下所示的文本框,假设在单击"确定"后会弹出覆盖带有无效数字消息的文本框条目,我希望显示之前覆盖的有效条目.

我怎么能在C#中做到这一点?

private void cor_o_gain_Validating(object sender, CancelEventArgs e)
{
    try
    {
        int entered = int.Parse(cor_o_gain.Text);
        if (entered > 255)
        {
            e.Cancel = true;
            MessageBox.Show("Enter the number between 0 and 255");
        }
    }
    catch (FormatException)
    {
      //  e.Cancel = true;
    }
} 
Run Code Online (Sandbox Code Playgroud)

cod*_*nix 6

您也可以简单地调用Undo()方法(如果您正在谈论Windows窗体TextBox)