简体   繁体   中英

C# Word Interop Automation 2013 - Set Font color to an RGB value

How do you set the FONT COLOR on a Microsoft.Office.Interop.Word C# application?

I noticed the ColorIndex property handles around 20 colors and no sign of allowing me choose from a RGB value ??

This is the code that I cannot make it work:

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

The exception i get is:
One of the values passed to this method or property is out of range.

Any help will be truly appreciated !!

Although Color doesn't appear in the intelisense, you can access it on Font like so:

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

And to create a custom WdColor, you can use:

Color c = Color.FromArgb(229, 223, 236);
var myWdColor = (Microsoft.Office.Interop.Word.WdColor)(c.R + 0x100 * c.G + 0x10000 * c.B);

尝试使用Font.TextColor.RGB

Just try this:

Color c = Color.FromArgb(84, 141, 212);            
parag.Range.Font.TextColor.RGB = (c.R + 0x100 * c.G + 0x10000 * c.B)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM