IVsColorableItem Interface

Provides default font colors, font style, and item name information for a custom colorable item.

Namespace:  Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)

Syntax

声明
<InterfaceTypeAttribute()> _
<GuidAttribute("56694A40-78D0-45DD-AB15-681BC207579C")> _
Public Interface IVsColorableItem
[InterfaceTypeAttribute()]
[GuidAttribute("56694A40-78D0-45DD-AB15-681BC207579C")]
public interface IVsColorableItem
[InterfaceTypeAttribute()]
[GuidAttribute(L"56694A40-78D0-45DD-AB15-681BC207579C")]
public interface class IVsColorableItem
[<InterfaceTypeAttribute()>]
[<GuidAttribute("56694A40-78D0-45DD-AB15-681BC207579C")>]
type IVsColorableItem =  interface end
public interface IVsColorableItem

The IVsColorableItem type exposes the following members.

Methods

  Name Description
Public method GetDefaultColors Defines the default background and foreground colors for a custom colorable item.
Public method GetDefaultFontFlags Returns the default font flags for the custom colorable item.
Public method GetDisplayName Gets the display name of the custom colorable item.

Top

Remarks

The display name for the custom colorable item should be localized.

The color values returned from this interface are predefined colors. High color (24-bit) values can be returned through the IVsHiColorItem interface. See the IVsHiColorItem interface for an example.

How to implement custom colorable items is described in Custom Colorable Items.

Notes to Implementers

Implement this interface to provide font and name information about a custom colorable item that is returned from a language service.

If you want to support high color values, you must implement the IVsHiColorItem interface on the same object that implements the IVsColorableItem interface.

Notes to Callers

An IVsColorableItem object can be obtained by calling the GetColorableItem method on the IVsProvideColorableItems interface.

Examples

This example is from a language service.

using Microsoft.VisualStudio.TextManager.Interop;

namespace MyNamespace
{
    internal class MyColorItem : IVsColorableItem
    {
        //==========================================================
        // Private fields.
        private COLORINDEX foreColor;
        private COLORINDEX backColor;
        private FONTFLAGS fontFlags;
        private string name;
        private string displayName;

        //==========================================================
        // Public constructor.

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


        //==========================================================
        // 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
    }


    //==============================================================
    // 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 MyColorableItem("MyLanguage- Operator",
                                    "MyLanguage- Operator",
                                    COLORINDEX.CI_DARKBLUE,
                                    COLORINDEX.CI_BLUE,
                                    FONTFLAGS.FF_PLAIN)
            };
        }
    }
}

See Also

Reference

Microsoft.VisualStudio.TextManager.Interop Namespace

Other Resources

Custom Colorable Items