How to get current used color theme of Visual Studio

前端 未结 3 1436
甜味超标
甜味超标 2020-12-10 05:49

I\'m creating my own IntelliSense Presenter, since Visual Studio2012 support change theme, so I want my background color of the presenter can be auto-changed when the theme

3条回答
  •  佛祖请我去吃肉
    2020-12-10 06:01

    Just wanted to put an update just in case anyone else comes along.. @Matze and @Frank are totally right.. However in VS 2015.. they added a easy way to detect the theme change. So you need to include PlatformUI an dyou get a super easy event

    using Microsoft.VisualStudio.PlatformUI;
    ....
     //Then you get an event 
     VSColorTheme.ThemeChanged += VSColorTheme_ThemeChanged;
    

    You should make sure your control is disposable so you can unsubscribe from the event...

    BONUS!

    It also give you easy access to the colors.. even if the user has changed them from the default .. so you can do stuff like this in when set your colors

    var defaultBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
    var defaultForeground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
    

提交回复
热议问题