I當按下提交按鈕而沒有強制字段中的任何數據時,將控件背景色設置爲紅色。但我需要在這些缺少的必填字段中輸入數據。當我開始輸入數據時,背景紅色變爲白色。是否有機會將所有其他必填字段顏色更改爲白色?vb.net上的控件組按鈕事件
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
這是我的代碼
你能告訴我們用你的代碼來更好地理解這個概念和問題? – Nianios
@HaBouF - 我的代碼如下: – Thanzeem
我看不到它。請在問題部分添加代碼。 – Nianios