ColorableItem.GetColorData(Int32, UInt32) Methode

Definition

Angegebenes Vordergrund- oder Hintergrundelement mit hoher Farbauflösung abrufen.

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

Parameter

cdElement
Int32

[in] Ein Wert aus der __tagVSCOLORDATA-Enumeration, der angibt, welches Farbenelement abgerufen werden soll.

crColor
UInt32

[out] Gibt ein COLORREF-Objekt zurück, das die RGB-Werte für das angegebene Farbenelement enthält.

Gibt zurück

Int32

Wenn die Ausführung erfolgreich ist, wird S_OK, andernfalls ein Fehlercode zurückgegeben.

Implementiert

Beispiele

Dies ist eine mögliche Implementierung dieser Methode (Dies ist vergleichbar mit der Basis Implementierung, die vom Managed Package Framework bereitgestellt wird).

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

Hinweise

Diese Methode ist eine Implementierung der- GetColorData Methode in der- IVsHiColorItem Schnittstelle.

Die Basis Methode gibt das Color-Element zurück, das an den Konstruktor für den Vordergrund ( cdElement Parameter = CD_FOREGROUND ) oder das Background ( cdElement Parameter =)-Element übergeben wurde CD_BACKGROUND .

Gilt für