예제 #1
0
        /// <summary>
        /// 设置textedit中的颜色
        /// </summary>
        /// <param name="name">例如"String",可以在工具-选项-字体和颜色中查看</param>
        /// <param name="foreColor">-1采用默认值</param>
        /// <param name="backColor">-1采用默认值</param>
        public static void SetTextEditColor(string name, int foreColor, int backColor)
        {
            var textEditorGuid = new Guid(textEditGuid);

            FontColorObject.OpenCategory(ref textEditorGuid, (uint)__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | (uint)__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS);
            try
            {
                ColorableItemInfo[] info = new ColorableItemInfo[1];
                if (FontColorObject.GetItem(name, info) == VSConstants.S_OK)
                {
                    if (foreColor != -1)
                    {
                        info[0].crForeground = (uint)foreColor;
                    }
                    if (backColor != -1)
                    {
                        info[0].crBackground = (uint)backColor;
                    }
                    FontColorObject.SetItem(name, info);
                }
            }
            finally
            {
                FontColorObject.CloseCategory();
            }
        }
예제 #2
0
        /// <summary>
        /// 获得textedit中的颜色
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Color GetTextEditColor(string name)
        {
            Guid textEditorGuid = new Guid(textEditGuid);

            FontColorObject.OpenCategory(ref textEditorGuid, (uint)__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | (uint)__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS);
            try
            {
                ColorableItemInfo[] info = new ColorableItemInfo[1];
                if (FontColorObject.GetItem(name, info) == VSConstants.S_OK)
                {
                    uint c = info[0].crForeground;
                    return(ConvertWindowsRGBToColour((int)c));
                }
                return(Color.Empty);
            }
            finally
            {
                FontColorObject.CloseCategory();
            }
        }