0

好的,此代码使您可以访问 VS 中的用户设置背景颜色:

        System.Guid guid = new System.Guid("{58E96763-1D3B-4E05-B6BA-FF7115FD0B7B}");

        IVsFontAndColorStorage fontAndColorStorage =
           Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider
           .GetService(typeof(SVsFontAndColorStorage)) as IVsFontAndColorStorage;
        if (fontAndColorStorage != null)
        {
            // GlobalValues.FontsAndColors_TextEditor is found in the registry: HKEY_USERS\.DEFAULT\Software\Microsoft\VisualStudio\[VS_VER]_Config\FontAndColo‌​rs\Text Editor, where VS_VER is the actual Visual Studio version: 10.0, 11.0, 12.0, 14.0, etc.
            if (fontAndColorStorage.OpenCategory(guid/*Microsoft.VisualStudio.Editor.DefGuidList.guidTextEditorFont‌​Category*/,
                (uint)__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS) == VSConstants.S_OK)
            {
                ColorableItemInfo[] info = new ColorableItemInfo[] { new ColorableItemInfo() };
                fontAndColorStorage.GetItem("Plain Text", info);

                fontAndColorStorage.CloseCategory();
            }
        }

我怎样才能得到实际System.Coloruint crBackground财产ColorableItemInfo???

4

1 回答 1

0

编辑:这并不总是有效 - 如果主题是白色,它会得到黑色。

                byte[] intBytesFO = BitConverter.GetBytes(info[0].crForeground);
                Color colBG = Color.FromArgb(intBytesBG[3], intBytesBG[0], intBytesBG[1], intBytesBG[2]);
于 2016-08-30T10:05:57.810 回答