C # Word Interop Automation 2013 - Set font color to RGB

How do you install FONT COLOR in a Microsoft.Office.Interop.Word C # application?

I noticed that the ColorIndex property handles about 20 colors and does not allow me to choose from a value of RGB

This is the code that I cannot get to work:

parag.Range.Font.TextColor.RGB = Color.FromArgb(84, 141, 212).ToArgb(); 

An exception I get:
One of the values ​​passed to this method or property is out of range.

Any help would be really appreciated!

+4
source share
3 answers

Try using Font.TextColor.RGB .

+2
source

Although the color does not appear in intelisense, you can access it in Font:

 parag.Range.Font.Color = WdColor.wdColorBlue; 

To create a custom WdColor, you can use:

 Color c = Color.FromArgb(229, 223, 236); var myWdColor = (Microsoft.Office.Interop.Word.WdColor)(cR + 0x100 * cG + 0x10000 * cB); 
+2
source

Just try the following:

 Color c = Color.FromArgb(84, 141, 212); parag.Range.Font.TextColor.RGB = (cR + 0x100 * cG + 0x10000 * cB) 
0
source

Source: https://habr.com/ru/post/1487969/


All Articles