• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Check color of button once clicked

Hi,

I am trying to check the color of a button using this code

If CType(sender, button).BackColor = System.Drawing.Color.ForestGreen Then
.....
End If

and get this error "Operator "=" is not defined for types System.Drawing.Color and System.Drawing.Color  "

Any ideas on how to resolve this
0
daly__paul
Asked:
daly__paul
  • 3
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
Hi daly__paul,

replace = with is.

"is" is used to check object.

Cheers!
0
 
daly__paulAuthor Commented:
Hi emoreau

With "Is" I get this error:

"'Is' requires operands that have reference types, but this has a value type System.Drawing.Color"
0
 
Éric MoreauSenior .Net ConsultantCommented:
try this
If CType(sender, Button).BackColor.ToKnownColor = KnownColor.ForestGreen Then
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
daly__paulAuthor Commented:
Get the original error
"Operator "=" is not defined for types System.Drawing.KnownColor and System.Drawing.Color  "
0
 
iboutchkineCommented:
try to use Equal operator

If color1.Equals(color2) Then
        ' color1 is the same named color as color2
    End If
0
 
daly__paulAuthor Commented:
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now