I Set the controls back ground color in Red when i press the submit button without any data in mandatory fields. But i need to re enter data in these missing mandatory fields. When i start to re enter data, the back ground red color goes white. Is there any chance to change all other mandatory fields color to White?
Private Sub TXTEMPID_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TXTEMPID.KeyPress
UncheckMyControls()
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub UncheckMyControls()
Dim txt, cmb, mtxt, rtxt As Control
For Each cmb In EMPGBDATA.Controls
If TypeOf cmb Is ComboBox Then
If cmb.BackColor = Color.Red Then
cmb.BackColor = Color.White
End If
End If
Next
For Each rtxt In EMPGBDATA.Controls
If TypeOf rtxt Is RichTextBox Then
If rtxt.BackColor = Color.Red Then
rtxt.BackColor = Color.White
End If
End If
Next
For Each mtxt In EMPGBDATA.Controls
If TypeOf mtxt Is MaskedTextBox Then
If mtxt.BackColor = Color.Red Then
mtxt.BackColor = Color.White
End If
End If
Next
For Each txt In EMPGBDATA.Controls
If TypeOf txt Is TextBox Then
If txt.BackColor = Color.Red Then
txt.BackColor = Color.White
End If
End If
Next
End Sub
This is my Code
As SolarBear suggested:
Now can you describe your problem exactly?
So after your comments:
You said that you are able to check if the mandatory fields are blank and if yes you are setting their backcolor to red. and you popUp as message.
After the message you want in the first time that the user try to type something in any of your textboxes to reset the color to white:
So after your comments2: