Compare two Color objects

前端 未结 3 1620
我寻月下人不归
我寻月下人不归 2020-12-03 14:14

This is VS2010 and .NET 4.0. I\'m trying to compare two System.Drawing.Color objects.

The value of mStartColor.ToArgb() is 16777215

3条回答
  •  悲哀的现实
    2020-12-03 15:05

    Colour structs have more data contained in them, than just the actual colour information, such as

    Color [Transparent] 
    R: 255 
    G: 255 
    B: 255 
    A: 0 
    IsKnownColor: True 
    IsEmpty: False 
    IsNamedColor: True 
    IsSystemColor: False 
    Name: Transparent 
    

    Color.FromArgb(16777215)

    Color [A=0, R=255, G=255, B=255] 
    R: 255 
    G: 255 
    B: 255 
    A: 0 
    IsKnownColor: False 
    IsEmpty: False 
    IsNamedColor: False 
    IsSystemColor: False 
    Name: ffffff 
    

    Equals comparisons will use all of these to determine equality. you should be diong what you already suggested, and use:

    Color.Transparent.ToArgb().Equals(mStartColor.ToArgb())
    

提交回复
热议问题