Share via


ColorableItem.GetColorData Method

Get the specified high color foreground or background element.

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)

Syntax

'Declaration
Public Overridable Function GetColorData ( _
    cdElement As Integer, _
    <OutAttribute> ByRef crColor As UInteger _
) As Integer
public virtual int GetColorData(
    int cdElement,
    out uint crColor
)
public:
virtual int GetColorData(
    int cdElement, 
    [OutAttribute] unsigned int% crColor
)
abstract GetColorData : 
        cdElement:int * 
        crColor:uint32 byref -> int  
override GetColorData : 
        cdElement:int * 
        crColor:uint32 byref -> int
public function GetColorData(
    cdElement : int, 
    crColor : uint
) : int

Parameters

  • cdElement
    Type: Int32

    [in] A value from the __tagVSCOLORDATA enumeration specifying which color element to retrieve.

  • crColor
    Type: UInt32%

    [out] Returns a COLORREF object that contains the RGB values for the specified color element.

Return Value

Type: Int32
If successful, returns S_OK; otherwise, returns an error code.

Implements

IVsHiColorItem.GetColorData(Int32, UInt32%)

Remarks

This method is an implementation of the GetColorData method in the IVsHiColorItem interface.

The base method returns the color element that was passed to the constructor for the foreground (cdElement parameter = CD_FOREGROUND) or background (cdElement parameter = CD_BACKGROUND) element.

Examples

This is one possible implementation of this method (this is similar to the base implementation supplied by the managed package framework).

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 Security

See Also

Reference

ColorableItem Class

Microsoft.VisualStudio.Package Namespace