我正在尝试自动验证我的c#应用程序

时间:2014-01-16 05:04:45

标签: c#

到目前为止应用程序正在运行,但我不知道如何自动验证,用户在文本框中输入一个数字,当用户点击按钮解析时,文本框永远不应为空,任何替代建议如何我可以验证应用程序将不胜感激

public Parse_Strings()
{
    InitializeComponent();
    this.AutoValidate = System.Windows.Forms.AutoValidate.Disable;
}

private void Parse_Strings_Load(object sender, EventArgs e)
{

}

private void btn_exit_Click(object sender, EventArgs e)
{
    this.Close();
}

private void btn_parse_Click(object sender, EventArgs e)
{

    string[] temp = txtenter.Text.Split(",".ToCharArray());
    {
       if (temp.Length == 3)
       {
          txtname.Text = temp[0];
          txtaccount.Text = temp[1];
          txtpassword.Text = temp[2];
       }
       else if (temp.Length > 0)
            {
               MessageBox.Show(" cannot be empty ");
            }
            else if (temp.Length >= 3)
                 {
                   MessageBox.Show(" entry is above required range ");
                 }

    }
}

1 个答案:

答案 0 :(得分:0)

为什么不在Button Parse点击事件中进行验证?像这样:

if(!string.IsNullOrEmpty(this.txtenter.Text) && 
       !(txtenter.Text.Replace(',' ,'').Any(x => char.IsLetter(x)))
{
     string[] temp = txtenter.Text.Split(',');
     ...

}
相关问题