ColorableItem.GetColorData 方法

获取指定深度颜色前台或后台元素。

命名空间:  Microsoft.VisualStudio.Package
程序集:   Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.10.0(在 Microsoft.VisualStudio.Package.LanguageService.10.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.11.0(在 Microsoft.VisualStudio.Package.LanguageService.11.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.9.0(在 Microsoft.VisualStudio.Package.LanguageService.9.0.dll 中)

语法

声明
Public Overridable Function GetColorData ( _
    cdElement As Integer, _
    <OutAttribute> ByRef crColor As UInteger _
) As Integer
public virtual int GetColorData(
    int cdElement,
    out uint crColor
)

参数

  • crColor
    类型:System.UInt32%
    [out] 返回包含指定的颜色的元素的 RGB 值的 COLORREF 对象。

返回值

类型:System.Int32
如果成功,则返回; S_OK否则,返回错误代码。

实现

IVsHiColorItem.GetColorData(Int32, UInt32%)

备注

此方法是 GetColorData 方法的实现。 IVsHiColorItem 接口的。

该基方法返回传递给前景的颜色的元素 (cdElement 参数为 CD_FOREGROUND) 或背景 (cdElement 参数为 CD_BACKGROUND) 元素的构造函数。

示例

这是此方法的一个可能实现 (这类似于托管包框架提供的基实现)。

using System.Drawing;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TextManager.Interop;

        public virtual int GetColorData(int cdElement, out uint crColor)
        {
            crColor = 0;

            if (hiForeColor.IsEmpty || hiBackColor.IsEmpty)
            {
                return VSConstants.E_FAIL;
            }

            switch (cdElement)
            {
                case (int)__tagVSCOLORDATA.CD_FOREGROUND:
                    crColor = ColorToRgb(this.hiForeColor);
                    break;
                case (int)__tagVSCOLORDATA.CD_BACKGROUND:
                    crColor = ColorToRgb(this.hiBackColor);
                    break;
                default:
                    return VSConstants.E_FAIL;
            }
            
            return VSConstants.S_OK;
        }

        uint ColorToRgb(Color color)
        {
             uint colorref = (uint)ColorTranslator.ToWin32(
                                        Color.FromArgb(color.R,
                                                       color.G,
                                                       color.B));
             return colorref;
        }

.NET Framework 安全性

请参见

参考

ColorableItem 类

Microsoft.VisualStudio.Package 命名空间