当我按下提交按钮时,我将控件的背景颜色设置为红色,而必填字段中没有任何数据。但我需要在这些缺失的必填字段中重新输入数据。当我开始重新输入数据时,背景红色变为白色。是否有机会将所有其他必填字段颜色更改为白色?
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
这是我的代码