Try it. It will also bring the color back when entering data.
For Each c As Control In Panel1.Controls If TypeOf c Is TextBox Then If c.Text = "" Then c.BackColor = Color.LightYellow Else c.BackColor = System.Drawing.SystemColors.Window End If End If Next
There is another way to do this, which involves creating an inherited TextBox control and using it in your form:
Public Class TextBoxCompulsory Inherits TextBox Overrides Property BackColor() As Color Get If MyBase.Text = "" Then Return Color.LightYellow Else Return DirectCast(System.Drawing.SystemColors.Window, Color) End If End Get Set(ByVal value As Color) End Set End Property End Class
Derek tomes
source share