You are creating a Windows Forms application for a courier company by using the .NET Framework 3.5. You create a form that allows customers to track the progress of their shipments.
The form contains the following elements:
* A text box named txtTN that allows users to enter a tracking number
*An ErrorProvider control named ErrorProvider1 that informs users of an invalid tracking number
* A function named ValidTrackingNumber that validates tracking numbers
You need to ensure that the txtTN text box is validated.Which code segment should you use?
A.
private void txtTN_Validating(object sender, CancelEventArgs e)
{
if (!ValidTrackingNumber(txtTN.Text))
{
errorProvider1.SetError(txtTN, “Invalid Tracking Number”);
e.Cancel = true;
}
else
errorProvider1.SetError(txtTN, “”);
}
B.
private void txtTN_Validating(object sender, CancelEventArgs e)
{
if (!ValidTrackingNumber(txtTN.Text))
errorProvider1.SetError(txtTN, “Invalid Tracking Number”);
else
{
errorProvider1.SetError(txtTN, “”);
e.Cancel = true;
}
}
C.
private void txtTN_Validated(object sender, EventArgs e)
{
If (!ValidTrackingNumber(txtTN.Text))
errorProvider1.SetError(txtTN, “Invalid Tracking Number”);
else
{
errorProvider1.SetError(txtTN, “”); txtTN.Focus();
}
}
D.
private void txtTN_Validated(object sender, EventArgs e)
{
if (!ValidTrackingNumber(txtTN.Text))
{
errorProvider1.SetError(txtTN, “Invalid Tracking Number”);
txtTN.Focus();
}
else errorProvider1.SetError(txtTN, “”);
}