Hello. I am building a data entry form. I have code that runs when the 'submit' button is clicked to check that all required fields are populated; if not, the missing fields are hilighted in red:
My problem arises when I want to reset the color back to normal. In my form when you click Cancel or move to a new record, all fields are disabled (set to read only) until the 'Edit' button is clicked. Visually this is represented by the field backgrounds being gray. VB.Net automatically changes the text box/combo boxes backcolor to gray when I disable them. However, once I have explicitly changed a control's backcolor, thereafter disabling it does not change its color to gray.
I have tried changing the backcolor to System.Drawing.SystemColors.Window, but the problem is the same. The control whose color has been changed is disabled (won't accept entry) but the backcolor remains white, no matter how many times DisableFields() is issued. So I end up with all the fields on the form being gray but one.
Any ideas? Thanks in advance...
VB.NET:
Sub validatefields()
saveOK = True
If Trim(Me.cmbBillCat.Text) = "" Then
saveOK = False
Me.cmbBillCat.Appearance.BackColor = Color.Tomato
End If
etc....
My problem arises when I want to reset the color back to normal. In my form when you click Cancel or move to a new record, all fields are disabled (set to read only) until the 'Edit' button is clicked. Visually this is represented by the field backgrounds being gray. VB.Net automatically changes the text box/combo boxes backcolor to gray when I disable them. However, once I have explicitly changed a control's backcolor, thereafter disabling it does not change its color to gray.
VB.NET:
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancel.Click
Me.cmbBillCat.Appearance.BackColor = Color.White
DisableFields()
Me.Refresh()
End Sub
Sub DisableFields()
Me.cmbBillCat.ReadOnly = True
End Sub
I have tried changing the backcolor to System.Drawing.SystemColors.Window, but the problem is the same. The control whose color has been changed is disabled (won't accept entry) but the backcolor remains white, no matter how many times DisableFields() is issued. So I end up with all the fields on the form being gray but one.
Any ideas? Thanks in advance...
Last edited: