簡體   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