/// <summary> /// Returns a standard VS color or a system color, if the VS colors service is not available /// </summary> /// <param name="visualStudioColor">Color enum</param> /// <returns>The color itself</returns> internal static Color GetVsColor(Vs2010Color visualStudioColor) { uint win32Color = 0; IVsUIShell2 vsuiShell2 = WixPackage.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell2; if (vsuiShell2 != null && vsuiShell2.GetVSSysColorEx((Int32)visualStudioColor, out win32Color) == VSConstants.S_OK) { Color color = ColorTranslator.FromWin32((int)win32Color); return(color); } // We need to fall back to some reasonable colors when we're not running in VS // to keep the forms/property pages editable in the designers switch (visualStudioColor) { case Vs2010Color.VSCOLOR_BUTTONFACE: return(SystemColors.ButtonFace); case Vs2010Color.VSCOLOR_BUTTONTEXT: return(SystemColors.ControlText); case Vs2010Color.VSCOLOR_WINDOW: return(SystemColors.Window); default: return(Color.Red); } }
private Color getVSColor(IVsUIShell2 uiShell2, __VSSYSCOLOREX color) { //get the COLORREF structure uint win32Color; uiShell2.GetVSSysColorEx((int)color, out win32Color); //translate it to a managed Color structure return(ColorTranslator.FromWin32((int)win32Color)); }
public ContentPreviewToolWindowControl() { InitializeComponent(); IVsUIShell2 shell = (IVsUIShell2)Package.GetGlobalService(typeof(SVsUIShell)); uint vsBackColor; shell.GetVSSysColorEx((int)__VSSYSCOLOREX.VSCOLOR_TOOLWINDOW_BACKGROUND, out vsBackColor); System.Drawing.Color backColor = System.Drawing.ColorTranslator.FromWin32((int)vsBackColor); graphicsDeviceControl.BackColor = backColor; }
/// <summary> /// Return a compatible <see cref="Brush"/> for the ToolWindowTextColorKey /// </summary> /// <param name="iVsUiShell2">The <see cref="IVsUIShell2"/> for surface handling inside Visual Studio</param> /// <returns>A compatible <see cref="Brush"/></returns> internal static Brush GetWindowTextColor(IVsUIShell2 iVsUiShell2 = null) { if (iVsUiShell2 == null) { return(Brushes.Black); } const int systemColor = (int)__VSSYSCOLOREX.VSCOLOR_TOOLWINDOW_TEXT; uint color; return(iVsUiShell2.GetVSSysColorEx(systemColor, out color) == VSConstants.S_OK ? GetThemedBrush(color) : Brushes.Black); }
private Dictionary <string, Color> GetVisualStudioDetailedColorList() { IVsUIShell2 uiShell = (IVsUIShell2)ChangesetViewerPackage.GetGlobalService(typeof(IVsUIShell)); Dictionary <string, Color> result = new Dictionary <string, Color>(); foreach (__VSSYSCOLOREX vsSysColor in Enum.GetValues(typeof(__VSSYSCOLOREX))) { uint win32Color; uiShell.GetVSSysColorEx((int)vsSysColor, out win32Color); Color color = ColorTranslator.FromWin32((int)win32Color); if (!result.Any(c => c.Key == vsSysColor.ToString())) { result.Add(vsSysColor.ToString(), color); } } return(result); }
public static void SetTheme(string chosen = null) { try { if (chosen == null) { chosen = Repository.Instance.Settings.FetchSettings <string>(Constants.Settings.SelectedThemeKey); } var oldTheme = _themeDic; var oldBaseTheme = _baseThemeDic; IVsUIShell2 uiShell = _package.GetService(typeof(SVsUIShell)) as IVsUIShell2; uint rgb; uiShell.GetVSSysColorEx((int)__VSSYSCOLOREX.VSCOLOR_TOOLWINDOW_BACKGROUND, out rgb); var col = System.Drawing.ColorTranslator.FromWin32((int)rgb); if (col.GetBrightness() < 0.5) { IsDarkTheme = true; _themeDic = new System.Windows.ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml") }; _baseThemeDic = new System.Windows.ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml") }; } else { IsDarkTheme = false; _themeDic = new System.Windows.ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml") }; _baseThemeDic = new System.Windows.ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml") }; } if (chosen != null && MahApps.Metro.ThemeManager.Accents.Any(accent => accent.Name == chosen)) { _themeDic = new System.Windows.ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/" + chosen + ".xaml") }; } foreach (var control in _themedControls) { if (control.Resources.MergedDictionaries.Contains(oldTheme)) { control.Resources.MergedDictionaries.Remove(oldTheme); } if (control.Resources.MergedDictionaries.Contains(oldBaseTheme)) { control.Resources.MergedDictionaries.Remove(oldBaseTheme); } if (!control.Resources.MergedDictionaries.Contains(_themeDic)) { control.Resources.MergedDictionaries.Add(_themeDic); } if (!control.Resources.MergedDictionaries.Contains(_baseThemeDic)) { control.Resources.MergedDictionaries.Add(_baseThemeDic); } control.UpdateDefaultStyle(); } } catch (Exception ex) { SimpleLogger.Log(ex); } }