0
我正在處理Windows窗體應用程序,並試圖驗證使用錯誤提供程序的幾個文本框,但問題是當我點擊選項卡1中存在的按鈕時,所有文本框甚至出現一個不同的標籤被驗證。我希望驗證發生在當前選項卡上的文本框中,而不是任何其他選項卡上的任何控件。我怎樣才能做到這一點?請幫忙。以下是與點擊事件中的驗證相關的代碼。使用ErrorProviders在窗體窗體的不同選項卡上驗證
private void btnCreateUser_Click(object sender, EventArgs e)
{
if (this.ValidateChildren(ValidationConstraints.Enabled))
{
// Some Code here
}
}
以下代碼用於驗證和驗證一個文本框的事件。我使用其他文本框的類似代碼以及其他選項卡上的代碼。
private void txtFirstNm_Validating(object sender, CancelEventArgs e)
{
bool cancel = false;
if (txtFirstNm.Text.Trim().Length == 0)
{
cancel = true;
errorProvider1.SetError(txtFirstNm,"Please enter First Name");
}
else
{
cancel = false;
errorProvider1.SetError(txtFirstNm, "");
}
e.Cancel = cancel;
}
private void txtFirstNm_Validated(object sender, EventArgs e)
{
errorProvider1.SetError(txtFirstNm,"");
}