Home All Groups Group Topic Archive Search About
Author
24 Nov 2007 10:32 PM
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.
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Author
24 Nov 2007 10:59 PM
Bob Powell [MVP]
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.


Show quoteHide quote
"Nathan Sokalski" <njsokal***@hotmail.com> wrote in message
news:%231rOinuLIHA.5400@TK2MSFTNGP04.phx.gbl...
> 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.
> --
> Nathan Sokalski
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
Author
24 Nov 2007 11:12 PM
Jack Jackson
On Sat, 24 Nov 2007 17:32:24 -0500, "Nathan Sokalski"
<njsokal***@hotmail.com> wrote:

>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>
Author
24 Nov 2007 11:20 PM
Herfried K. Wagner [MVP]
"Nathan Sokalski" <njsokal***@hotmail.com> schrieb:
> 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>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>