473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Color Equality

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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 24 '07 #1
2 1537
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" <nj********@hotmail.comwrote in message
news:%2****************@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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 24 '07 #2
On Sat, 24 Nov 2007 17:32:24 -0500, "Nathan Sokalski"
<nj********@hotmail.comwrote:
>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>
Nov 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug Holland | last post by:
Currently I am responsible for writing the C# coding standards document for a client and I have been doing some investigations with ildasm to establish some additional best practices. When using...
1
by: gi75research | last post by:
What should be a very simple function is going terribly wrong, and I don't know why. StartTime and EndTime are table values (formatted like "01:00A" or "02:00P"); DaypartStart and DaypartEnd are...
40
by: Ike Naar | last post by:
In K&R "The C++ programming language (2nd ANSI C edition), the reference manual states (paragraphs 7.9 and 7.10) that pointer comparison is undefined for pointers that do not point to the same...
4
by: Matt Burland | last post by:
I'm a little confused about the way the default equality operator works with classes. Here's the situation, I have two comboboxes that are each filled with different object (i.e. ComboBox1 contains...
2
by: Marcel Sottnik | last post by:
Hallo NG Does anyone have an idea how could one implement, a general routine for value equality ? I mean something using Reflections to get all the members of a class and compare them...
6
by: onetitfemme | last post by:
Hi *, I have been looking for a definition or at least some workable concept of "XML equality". Searching on "XML equality" in comp.text.xml, microsoft.public.xsl and microsoft.public.xml...
6
by: Edward Diener | last post by:
Now that operator overloading allows to ref classes to be compared for equality using == syntax, how does one compare the actual ref pointers ( ^ ) for equality instead ? As an example: ...
12
by: John Smith | last post by:
This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b)...
3
by: toton | last post by:
Hi, I have a struct Point { int x, int y; } The points are stored in a std::vector<Pointpoints; (global vector) I want to add equality (operator == ) for the point, which will check equality...
16
by: DamienS | last post by:
In the interests of me saving hair, can someone please explain to me what's going on below? Why doesn't == work in comparing two int's when cast as objects? They're the same type. Note that it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.