Convert System.Color To Microsoft Word WdColor

前端 未结 3 650
半阙折子戏
半阙折子戏 2021-01-17 19:47

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 i

相关标签:
3条回答
  • 2021-01-17 20:05

    I thought people might like an extension method:

        public static void ColorRGB(this Wd.Font font, int red, int green, int blue)
        {
            font.Color = (Wd.WdColor)(red + 0x100 * green + 0x10000 * blue);
        }
    
    0 讨论(0)
  • 2021-01-17 20:13
    Color c = Colors.Blue;
    var wdc = (Microsoft.Office.Interop.Word.WdColor)(c.R + 0x100 * c.G + 0x10000 * c.B);
    
    0 讨论(0)
  • 2021-01-17 20:25

    Add a Reference to Microsoft.VisualBasic dll

    using Microsoft.VisualBasic;
    
    int rgbColor = Information.RGB(100, 150, 75);
    Word.WdColor wdColor = (Word.WdColor)rgbColor;
    
    0 讨论(0)
提交回复
热议问题