Click here to Skip to main content
15,881,173 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Get Known Color from int value

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
20 Nov 2009CPOL 7.1K   1  
I think you are confusing how the FromArgb method works. It takes a 32 bit number in the format AARRGGBB, where each element of the color is an 8 bit number of the value 0 to 255. Setting the color to zero creates a black color, but it is transparent (the alpha channel is zero). To set black with an

I think you are confusing how the FromArgb method works. It takes a 32 bit number in the format AARRGGBB, where each element of the color is an 8 bit number of the value 0 to 255. Setting the color to zero creates a black color, but it is transparent (the alpha channel is zero). To set black with an opaque color, you need to add 4278190080 to the value (0xFF000000), which is basically ORing 0xFF000000 with the desired color. You can either do that, or remember to set the Color.A channel to 255 after you call FromArgb() in your code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President 6D Systems LLC
United States United States
I studied Software Engineering at Milwaukee School of Engineering for 2 years before switching to Management of Information Systems for a more business oriented approach. I've been developing software since the age of 14, and have waded through languages such as QBasic, TrueBasic, C, C++, Java, VB6, VB.NET, C#, etc. I've been developing professionally since 2002 in .NET.

Comments and Discussions

 
-- There are no messages in this forum --