繁体   English   中英

C#Word Interop Automation 2013-将字体颜色设置为RGB值

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

如何在Microsoft.Office.Interop.Word C#应用程序上设置字体颜色?

我注意到ColorIndex属性处理大约20种颜色,没有迹象表明我可以从RGB值中进行选择?

这是我无法使其工作的代码:

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

我得到的例外是:
传递给此方法或属性的值之一超出范围。

任何帮助将不胜感激!

尽管“颜色”没有出现在智能感知中,但是您可以像下面这样在“字体”上进行访问:

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

要创建自定义WdColor,可以使用:

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

尝试一下:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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