Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert System.Color To Microsoft Word WdColor

Tags:

c#

colors

I'm rather new to C# and find it almost unspeakable that there isn't a simple way for converting an RGB color or system.color to a WdColor!

VB is simple, C# - is it really that hard to do?

I do not want to reference VB in my project.

I'm using this in some word automation project to color a font, e.g.

tmpRange.Find.Replacement.Font.Color = Color.FromArgb(100, 150, 75); 

But this above line isn't possible, it needs to be a WdColor.

like image 279
user1320651 Avatar asked Oct 25 '12 18:10

user1320651


1 Answers

Color c = Colors.Blue;
var wdc = (Microsoft.Office.Interop.Word.WdColor)(c.R + 0x100 * c.G + 0x10000 * c.B);
like image 51
Cole Cameron Avatar answered Sep 19 '22 18:09

Cole Cameron