ColorableItem.GetColorData(Int32, UInt32) Метод

Определение

Получить указанный элемент переднего плана или фона высокой цветности.

public:
 virtual int GetColorData(int cdElement, [Runtime::InteropServices::Out] System::UInt32 % crColor);
 virtual int GetColorData(int cdElement, [Runtime::InteropServices::Out] unsigned int & crColor);
public virtual int GetColorData (int cdElement, out uint crColor);
abstract member GetColorData : int * uint32 -> int
override this.GetColorData : int * uint32 -> int
Public Overridable Function GetColorData (cdElement As Integer, ByRef crColor As UInteger) As Integer

Параметры

cdElement
Int32

[in] Значение из перечисления __tagVSCOLORDATA, указывающее, какой цветовой элемент необходимо извлечь.

crColor
UInt32

[out] Возвращает объект COLORREF, которые содержит значения RGB для указанного цветового элемента.

Возвращаемое значение

Int32

Возвращает значение S_OK, если выполнение прошло успешно; в противном случае возвращает код ошибки.

Реализации

Примеры

Это одна из возможных реализаций этого метода (аналогична базовой реализации, предоставляемой платформой управляемых пакетов).

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;  
        }  

Комментарии

Этот метод является реализацией GetColorData метода в IVsHiColorItem интерфейсе.

Базовый метод возвращает элемент Color, который был передан в конструктор для элемента переднего плана ( cdElement Parameter = CD_FOREGROUND ) или Background ( cdElement Parameter = CD_BACKGROUND ).

Применяется к