如何转换的System.Drawing.Color微软互操作WdColorIndex [英] How to convert System.Drawing.Color to Microsoft Interop WdColorIndex

查看:711
本文介绍了如何转换的System.Drawing.Color微软互操作WdColorIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换的System.Drawing.Color Microsoft.Office.Interop.Word.WdColorIndex <? / p>

我也做了到目前为止的代码,但它显示的错误溢出。



下面是代码我已经做了

 颜色的bgcolor = Color.FromArgb(Convert.ToInt32(的innerText)); 
Microsoft.Office.Interop.Word.WdColorIndex瓦轴集团=(Microsoft.Office.Interop.Word.WdColorIndex)(bgcolor.R + 0x100的* bgcolor.G + 0x10000的* bgcolor.B);
doc.Range(iRangeStart,iRangeEnd).HighlightColorIndex =瓦轴集团;



我怎样才能做到这一点?


解决方案

WdColorIndex 是一个枚举,而不是定义色彩系统中的对象。这意味着您可以分配值由枚举元素,例如限制 wdBlack wdBlue 及其基本的整数值。



您所使用的技术将被应用到 WdColor 对象,而不是一个 WdColorIndex 枚举:

  VAR wordColor =(Microsoft.Office.Interop.Word.WdColor)(bgcolor.R + 0x100的* bgcolor.G + 0x10000的* bgcolor.B) ; 



在Word文档中突出仅限于数量的颜色,如<$ C $定义C> WdColorIndex 枚举。因此,不能简单地任何颜色转换到Word颜色突出显示。你必须选择可用值之一。请参见 MSDN为WdColorIndex 的可能的值。


How can I convert System.Drawing.Color to Microsoft.Office.Interop.Word.WdColorIndex?

I have done the code so far, but it's showing the error "overflow".

Here is the code which I have done

Color bgcolor = Color.FromArgb(Convert.ToInt32(innerText));
Microsoft.Office.Interop.Word.WdColorIndex wbgc = (Microsoft.Office.Interop.Word.WdColorIndex)(bgcolor.R + 0x100 * bgcolor.G + 0x10000 * bgcolor.B);
doc.Range(iRangeStart, iRangeEnd).HighlightColorIndex = wbgc;

How can I achieve this?

解决方案

WdColorIndex is an enumeration, not an object that defines a color system. This means that the value you can assign is limited by the enumeration elements, e.g. wdBlack or wdBlue and their underlying integer values.

The technique you are using is to be applied to a WdColor object instead of a WdColorIndex enumeration:

var wordColor = (Microsoft.Office.Interop.Word.WdColor)(bgcolor.R + 0x100 * bgcolor.G + 0x10000 * bgcolor.B);

Highlighting in a Word document is limited to a number of colors, as defined in the WdColorIndex enumeration. Therefore, you cannot simply convert any color to a Word color for highlighting. You have to pick one of the available values. See MSDN for WdColorIndex for possible values.

这篇关于如何转换的System.Drawing.Color微软互操作WdColorIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆