Получить цвет фона Visual Studio из ColorableItemInfo
Хорошо, этот код дает вам доступ к пользовательскому цвету фона в 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\FontAndColors\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.guidTextEditorFontCategory*/,
(uint)__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS) == VSConstants.S_OK)
{
ColorableItemInfo[] info = new ColorableItemInfo[] { new ColorableItemInfo() };
fontAndColorStorage.GetItem("Plain Text", info);
fontAndColorStorage.CloseCategory();
}
}
Как я могу получить фактический System.Color
вне uint crBackground
собственностью ColorableItemInfo
???
1 ответ
РЕДАКТИРОВАТЬ: ЭТО НЕ ВСЕГДА РАБОТАЕТ - ЕСЛИ ТЕМА БЕЛАЯ, ЭТО ПОЛУЧАЕТ ЧЕРНЫЙ ЦВЕТ.
byte[] intBytesFO = BitConverter.GetBytes(info[0].crForeground);
Color colBG = Color.FromArgb(intBytesBG[3], intBytesBG[0], intBytesBG[1], intBytesBG[2]);