다음을 통해 공유


ColorableItem.GetColorData Method

Get the specified high color foreground or background element.

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

Syntax

‘선언
Public Overridable Function GetColorData ( _
    cdElement As Integer, _
    <OutAttribute> ByRef crColor As UInteger _
) As Integer
‘사용 방법
Dim instance As ColorableItem
Dim cdElement As Integer
Dim crColor As UInteger
Dim returnValue As Integer

returnValue = instance.GetColorData(cdElement, _
    crColor)
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

  • 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.

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

ColorableItem Members

Microsoft.VisualStudio.Package Namespace