Checking control forecolor (Comparison operator)

mza1979m

Newcomer
Joined
Feb 20, 2003
Messages
13
Location
London, Ontario
In VB.NET, what is the syntax for checking the forecolor of a certain control? For instance, I want to check if the forecolor of my GroupBox control is Red, and if so, perform a certain action. I tried the following, but no luck:

If grpTextAttributes.ForeColor = System.Drawing.Color.Red Then
' Block of code here
End If
 
Comparing the ForeColor the way you're showing works fine for me. Are you sure it's actually System.Drawing.Color.Red and not just the color "red"?

I tried this by using the ForeColor property of a TextBox and a GroupBox control, both worked just fine. I used C# but I don't think it would make a difference.

-Ner
 
Well, when I use the code I displayed above, I get the following error:

Operator '=' is not defined for types 'System.Drawing.Color' and 'System.Drawing.Color'.

When I use just 'Red' instead of 'System.Drawing.Color.Red', it says that the name 'Red' is not declared.
 
Weird, you can do this in C#. Try this instead:
Visual Basic:
        If TextBox1.ForeColor.Equals(System.Drawing.Color.Red) Then
            Debug.WriteLine("red")
        Else
            Debug.WriteLine("not red")
        End If

-Nerseus
 
Back
Top