4

In vb .net, how to typecast System.Color (or) Color.FromArgb(....) To Microsoft.Office.Interop.Word.WdColor?

Sai
  • 67
  • 1
  • 8
  • 1
    Looks like this has already been answered, but in c#, not vb: http://stackoverflow.com/a/13075575 if you can't read c#, then if run that answer through a c# to vb converter (there are plenty of them online if you google them) – stormCloud Mar 26 '16 at 18:15

1 Answers1

3

See the C# answer here.

You need to convert it to a hexadecimal style RGB:

To quote Cole Cameron's comment from that answer:

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.

Example (Converted from Cole Cameron's C# example):

Dim c As Color = Colors.Blue
Dim wdc = DirectCast(c.R + &H100 * c.G + &H10000 * c.B, Microsoft.Office.Interop.Word.WdColor)
Community
  • 1
  • 1
vbnet3d
  • 1,151
  • 1
  • 19
  • 37