Random Post: Defeating Antivirus System Pro
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About
  • Eric’s Toolset
  • Free Software
  • Software License
  •  

    .NET Color Struct Equality

    December 16th, 2009 by Eric

    When is white not white? When one is Color.White and the other is Color.FromArgb(0xff, 0xff, 0xff, 0xff).

    I was trying to data bind a list of colors to a ComboBox and have the SelectedValue property bound to a particular color. The frustrating thing was that even though there was a color matching the “selected” color in the list, the ComboBox never had a selection when first displayed.

    Eventually I discovered that my “selected” color was white (all color components at 255) while the list’s equivalent was Color.White. Careful reading of the Color.Equals documentation tells me that I was silly to think that white is white or black is black:

    Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not.

    Leave a Reply