.net – 如何将转换System.Color转换为Microsoft Word WdColor?

前端之家收集整理的这篇文章主要介绍了.net – 如何将转换System.Color转换为Microsoft Word WdColor?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在vb .net中,如何将System.Color(或)Color.FromArgb(….)强制转换为Microsoft.Office.Interop.Word.WdColor?

解决方法

the C# answer here.

您需要将其转换为十六进制样式RGB:

引用Cole Cameron对该答案的评论

Sum the Red,Green,and Blue values of the named color,multiplying the Green & Blue values by hexadecimal modifiers so that the value is effectively 0xBBGGRR (base doesn’t really matter,an integer’s an integer),then cast that to the WdColor enumeration type.

示例(转换自Cole Cameron的C#示例):

Dim c As Color = Colors.Blue
Dim wdc = DirectCast(c.R + &H100 * c.G + &H10000 * c.B,Microsoft.Office.Interop.Word.WdColor)

猜你在找的Windows相关文章