HighTechTalks DotNet Forums  

Color Equality

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Color Equality in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default Color Equality - 11-24-2007 , 04:32 PM






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
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Color Equality - 11-24-2007 , 04:59 PM






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.


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote

Quote:
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
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #3  
Old   
Jack Jackson
 
Posts: n/a

Default Re: Color Equality - 11-24-2007 , 05:12 PM



On Sat, 24 Nov 2007 17:32:24 -0500, "Nathan Sokalski"
<njsokalski (AT) hotmail (DOT) com> wrote:

Quote:
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>


Reply With Quote
  #4  
Old   
Herfried K. Wagner [MVP]
 
Posts: n/a

Default Re: Color Equality - 11-24-2007 , 05:20 PM



"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> schrieb:
Quote:
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/>



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.