Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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.

  • *Experts*
Posted

Weird, you can do this in C#. Try this instead:

       If TextBox1.ForeColor.Equals(System.Drawing.Color.Red) Then
           Debug.WriteLine("red")
       Else
           Debug.WriteLine("not red")
       End If

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...