共用方式為


IVsHiColorItem 介面

提供支援傳回完整的 24 位元色彩值。

命名空間:  Microsoft.VisualStudio.TextManager.Interop
組件:  Microsoft.VisualStudio.TextManager.Interop.8.0 (在 Microsoft.VisualStudio.TextManager.Interop.8.0.dll 中)

語法

'宣告
<InterfaceTypeAttribute()> _
<GuidAttribute("16C240B3-4773-43C2-932A-1E8DD2F6F0F8")> _
Public Interface IVsHiColorItem
[InterfaceTypeAttribute()]
[GuidAttribute("16C240B3-4773-43C2-932A-1E8DD2F6F0F8")]
public interface IVsHiColorItem
[InterfaceTypeAttribute()]
[GuidAttribute(L"16C240B3-4773-43C2-932A-1E8DD2F6F0F8")]
public interface class IVsHiColorItem
[<InterfaceTypeAttribute()>]
[<GuidAttribute("16C240B3-4773-43C2-932A-1E8DD2F6F0F8")>]
type IVsHiColorItem =  interface end
public interface IVsHiColorItem

IVsHiColorItem 類型會公開下列成員。

方法

  名稱 描述
公用方法 GetColorData 擷取指定之項目的 RGB 值。

回頁首

備註

這個介面用來提供支援 24 位元] 或 [高的色彩值。 它實作相同類別上實作IVsColorableItemIVsPackageDefinedTextMarkerType介面。

實作者注意事項

如果高的支援色彩值需長度,必須實作相同類別上實作這個介面IVsColorableItemIVsPackageDefinedTextMarkerType介面。

呼叫者注意事項

如果這個介面可以取得從物件實作IVsColorableItemIVsPackageDefinedTextMarkerType介面,那麼該物件就是高的色彩值的廣告支援。 呼叫GetColorData的個別前景、 背景和線條色彩的方法來取得 RGB 值。 如果GetColorData方法會傳回錯誤,依正常程序改為使用存取原始色彩IVsColorableItemIVsPackageDefinedTextMarkerType介面。

範例

以下是如何實作的 managed 程式碼中的 [範例IVsHiColorItem介面與它具現化。 請注意如何將一組紅色、 綠色和藍色值轉換成COLORREF在MyRGB建構函式。 本範例為語言服務。

using Microsoft.VisualStudio.TextManager.Interop;

namespace MyNamespace
{
    internal struct MyRGB
    {
        public uint ColorRef;

        public MyRGB(int r, int g, int b)
        {
            ColorRef = (uint)System.Drawing.ColorTranslator.ToWin32(
                                 System.Drawing.Color.FromArgb(r, g, b));
        }
        public MyRGB(bool fInvalid)
        {
            ColorRef = unchecked((uint)-1);
        }

        public bool IsValid()
        {
            return ColorRef != unchecked((uint)-1);
        }
    }


    internal class MyColorItem : IVsColorableItem, IVsHiColorItem
    {
        // Indicates that the returned RGB value is really an index
        // into a predefined list of colors.
        private const uint COLOR_INDEXED = 0x01000000;

        //==========================================================
        // Private fields.
        private COLORINDEX foreColor;
        private COLORINDEX backColor;
        private FONTFLAGS  fontFlags;
        private MyRGB      foreRGB;
        private MyRGB      backRGB;
        private string     name;
        private string     displayName;

        //==========================================================
        // Public constructors.

        public MyColorItem(string name,
                           string displayName,
                           COLORINDEX foreColor,
                           COLORINDEX backColor,
                           FONTFLAGS fontFlags)
        {
            this.name        = name;
            this.displayName = displayName;
            this.foreColor   = foreColor;
            this.backColor   = backColor;
            this.fontFlags   = fontFlags;
            this.foreRGB     = new MyRGB(false);
            this.backRGB     = new MyRGB(false);
        }

        public MyColorItem(string name,
                           string displayName,
                           COLORINDEX foreColor,
                           COLORINDEX backColor,
                           FONTFLAGS fontFlags,
                           MyRGB foreRGB,
                           MyRGB backRGB)
        {
            this.name        = name;
            this.displayName = displayName;
            this.foreColor   = foreColor;
            this.backColor   = backColor;
            this.fontFlags   = fontFlags;
            this.foreRGB     = foreRGB;
            this.backRGB     = backRGB;
        }

        //==========================================================
        // IVsColorableItem methods.
        #region IVsColorableItem Members

        int IVsColorableItem.GetDefaultColors(COLORINDEX[] piForeground,
                                              COLORINDEX[] piBackground)
        {
            int retval = VSConstants.E_POINTER;
            if (piForeground != null)
            {
                piForeground[0] = this.foreColor;
                retval = VSConstants.S_OK;
            }
            if (piBackground != null)
            {
                piBackground[0] = this.backColor;
            }
            return retval;
        }

        int IVsColorableItem.GetDefaultFontFlags(out uint pdwFontFlags)
        {
            pdwFontFlags = (uint)this.fontFlags;
            return VSConstants.S_OK;
        }

        int IVsColorableItem.GetDisplayName(out string pbstrName)
        {
            pbstrName = this.displayName;
            return VSConstants.S_OK;
        }

        #endregion


        //==========================================================
        // IVsHiColorItem methods.
        #region IVsHiColorItem Members

        int IVsHiColorItem.GetColorData(int cdElement, out uint pcrColor)
        {
            int retval = VSConstants.E_NOTIMPL;
            pcrColor = 0;

            switch ((__tagVSCOLORDATA)cdElement)
            {
                case __tagVSCOLORDATA.CD_BACKGROUND:
                    pcrColor = this.backRGB.IsValid() ?
                                   this.backRGB.ColorRef :
                                   (uint)backColor | COLOR_INDEXED;
                    retval = VSConstants.S_OK;
                    break;

                case __tagVSCOLORDATA.CD_FOREGROUND:
                case __tagVSCOLORDATA.CD_LINECOLOR:
                    pcrColor = this.foreRGB.IsValid() ?
                                   this.foreRGB.ColorRef :
                                   (uint)foreColor | COLOR_INDEXED;
                    retval = VSConstants.S_OK;
                    break;

                default:
                    retval = VSConstants.E_INVALIDARG;
                    break;
            }
            return retval;
        }

        #endregion
    }


    //==============================================================
    // Example of how to instantiate the MyColorItem class.

    public class MyLanguageService
    {
        private ColorableItem[] colorableItemsList;

        public MyLanguageService()
        {
            colorableItemsList = {
                new MyColorableItem("MyLanguage- Text",
                                    "MyLanguage- Text",
                                    COLORINDEX.CI_SYSPLAINTEXT_FG,
                                    COLORINDEX.CI_SYSPLAINTEXT_BK,
                                    FONTFLAGS.FF_BOLD),

                new MyColorableItem("MyLanguage- Keyword",
                                    "MyLanguage- Keyword",
                                    COLORINDEX.CI_MAROON,
                                    COLORINDEX.CI_SYSPLAINTEXT_BK,
                                    FONTFLAGS.FF_BOLD,
                                    new MyRGB(192,64,0),
                                    new MyRGB(false)),

                new MyColorableItem("MyLanguage- Operator",
                                    "MyLanguage- Operator",
                                    COLORINDEX.CI_DARKBLUE,
                                    COLORINDEX.CI_BLUE,
                                    FONTFLAGS.FF_PLAIN,
                                    new MyRGB(0,64,192),
                                    new MyRGB(128,128,255))
            };
        }
    }
}

請參閱

參考

Microsoft.VisualStudio.TextManager.Interop 命名空間