ColorableItem::GetColorData Method (Int32, UInt32)

 

Get the specified high color foreground or background element.

Namespace:   Microsoft.VisualStudio.Package
Assembly:  Microsoft.VisualStudio.Package.LanguageService.14.0 (in Microsoft.VisualStudio.Package.LanguageService.14.0.dll)

public:
virtual int GetColorData(
	int cdElement,
	[OutAttribute] unsigned int% crColor
)

Parameters

cdElement
Type: System::Int32

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

crColor
Type: System::UInt32

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

Return Value

Type: System::Int32

If successful, returns S_OK; otherwise, returns an error code.

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.

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;
        }
Return to top
Show: