Have a HEX
colour code string in the database ("#ADD8E6"
) and I want to use this to change the background colour of a MigraDoc
cell. I have found Color.Parse()
function, however it isn't changing the colour of my cell. I have had to do the following:
string colourHex = (database.HexCode).Replace("#", "0x");
var colourObject = MigraDoc.DocumentObjectModel.Color.Parse(colourHex);
Cell.Shading.Color = colourObject;
I know that the Cell.Shading.Color
is correct because if I apply Cell.Shading.Color = Colors.AliceBlue
then the cell does change colour as expected. I understand the Color.Parse
requires the HEX
code to start with 0x
rather than #
. I tried using the #
and it failed... At least with what I have got it is rendering... just not with my colour.
You have to replace "#" with "0xff" to get what you want.
With your short numbers (three components only) the alpha channel will always be 0 and the colour will be completely transparent. With 0xff
followed by six hex digits for the RGB colours you get a colour with full opacity.
Update: With the current version of MigraDoc 1.50 (beta 5b or later) you can also use the hash sign followed by 3, 6, or 8 hex digits. 8 digits include the alpha channel, with 3 or 6 digits an alpha setting of FF is used.
With the new version, the code #ADD8E6
will have the expected effect.
Nothing has changed when the 0x
prefix is used.