Color Equality

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

Is there a way to check whether two Colors are equal? If the Colors have
different Name properties, the = operator will return false even if the
A,R,G, and B properties are equal. I would like to be able to check whether
two colors are equal based only on the properties that determine what color
will be displayed. Is there a way to do this without writing my own method?
Thanks.
 
Both the Equals method and the = operator check for known colours. The only
way to check colour equality in a numerical manner is to compare the RGB
value. Probably the easiest way is to convert to integer and compare those.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Is there a way to check whether two Colors are equal? If the Colors have
different Name properties, the = operator will return false even if the
A,R,G, and B properties are equal. I would like to be able to check whether
two colors are equal based only on the properties that determine what color
will be displayed. Is there a way to do this without writing my own method?
Thanks.

If color1.ToArgb() = color2.ToArgb() Then

See
<http://msdn2.microsoft.com/en-us/library/system.drawing.color.equals(vs.71).aspx>
 
Nathan Sokalski said:
Is there a way to check whether two Colors are equal? If the Colors have
different Name properties, the = operator will return false even if the
A,R,G, and B properties are equal. I would like to be able to check
whether two colors are equal based only on the properties that determine
what color will be displayed.

See: <URL:http://www.jelovic.com/weblog/e140.htm>
 
Back
Top