我只爲方法創建類,所以我可以在我的項目中一直使用它們。目前我正在嘗試爲文本框驗證做一個方法,但我遇到了一些問題。通過方法驗證TextBox
我使用這個:
public bool ValidateIntTextBoxes(params TextBox[] textBox)
{
int value = 0;
return int.TryParse(textBox.ToString(), out value);
}
而我使用它是這樣的:
public bool IsValid()
{
return ValidateIntTextBoxes(AgeTextBox);
}
private void OKButton_Click(object sender, EventArgs e)
{
//This if statement is just to test the mothod
if(IsValid())
{
MessageBox.Show("Success");
}
else
{
AgeTextBox.BackColor = Color.Red;
}
}
的問題是,在isValid()方法,始終返回false。我究竟做錯了什麼 ?
這個完美的,我想要的。非常感謝您的參與。歡呼;) – Etrit
不客氣@ user2302998 –