2014-01-16 93 views
0

到目前爲止應用程序正在工作,但我不知道如何自動驗證,用戶在文本框中輸入一個數字,並且當用戶單擊按鈕分析時文本框不應該爲空,任何替代建議如何我可以驗證的應用程序,將不勝感激我想自動驗證我的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 "); 
       } 

    } 
} 
+0

請告訴我們正確的代碼。此代碼被不正確地加強/格式化。 –

回答

0

你爲什麼不使你的驗證在Button Parse點擊事件?像這樣:

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

} 
相關問題