次の方法で共有


ColorableItem.GetColorData(Int32, UInt32) Method

Definition

Get the specified high color foreground or background element.

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

Parameters

cdElement
Int32

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

crColor
UInt32

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

Returns

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

Implements

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

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.

Applies to