Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am using wpf and c#
how to set background property of a control to a particular colourcode using c#
Posted

See http://msdn.microsoft.com/en-us/library/system.windows.controls.control.background(v=vs.110).aspx[^]. For numeric colours use a string in the form of "#rgb", using the hex values 0 through F, or 00 through FF for each character position. Thus "#F00" and "#FF0000" both represent the colour red.
 
Share this answer
 
There isn't an easy way to get the colour with alpha included from a hex string in this way.

I think your answer depends on where you're getting the colour and alpha values from.

The RGB colour alone can be parsed from an HTML hex string:

Color colour = ColorTranslator.FromHtml("#E7EFF2");

If you have a separate alpha value you can then apply this (docs):

Color colour = ColorTranslator.FromHtml("#E7EFF2");
Color transparent = Color.FromArgb(128, colour);

Alternatively you may need to parse the string and split it out to convert the hex pairs into integer values.

PS excuse English spelling, but colour should definitely have a 'u' in it :)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900