比较两个 Color 对象 [英] Compare two Color objects
问题描述
这是 VS2010 和 .NET 4.0.我正在尝试比较两个 System.Drawing.Color
对象.
This is VS2010 and .NET 4.0. I'm trying to compare two System.Drawing.Color
objects.
mStartColor.ToArgb()
的值为 16777215
.
Color.Transparent.ToArgb()
的值为 16777215
.
mStartColor <>的值Color.Transparent
是 True
.
如何为 Color
对象实现相等性?
How is equality implemented for Color
objects?
谢谢大家.我得到了我的答案,尽管这对我来说没有多大意义(请参阅下面我对 Tim 和 Dave 的回答的评论).我会将 Tim 的帖子标记为答案,他是第一个回复的人,但 Dave 的回答同样提供了丰富的信息.
Thanks everyone. I got my answer, though it doesn't make much sense to me (see my comments to Tim's and Dave's answers below). I'll mark Tim's post as the answer and he was the first to reply, but Dave's answer is equally informative.
推荐答案
始终阅读 文档 首先:
"要仅根据 ARGB 值比较颜色,您应该使用ToArgb 方法.这是因为 Equals 和 Equality 成员不仅仅使用 ARGB 值来确定等效性颜色.例如,不考虑 Black 和 FromArgb(0,0,0)相等,因为黑色是命名颜色而 FromArgb(0,0,0) 不是"
"To compare colors based solely on their ARGB values, you should use the ToArgb method. This is because the Equals and Equality members determine equivalency using more than just the ARGB value of the colors. For example, Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not"
这篇关于比较两个 Color 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!