Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

431
Visualizações
Changing "Color theme" within a Visual Studio Extension

I'm writing a Visual Studio extension in C# that I hope will change the color theme depending on the time of day (After sunset the dark theme will be applied - at sunrise either the blue/light theme will be applied depending on the users preference).

I'm able to change the color theme using the WriteableSettingsStore exposed by a ShellSettingsManager object. When I execute the following code, the theme changes after restarting Visual Studio.

var settingsManager = new ShellSettingsManager(this);
var writeableUserStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

writeableUserStore.SetString("General", "CurrentTheme", GuidList.guidDarkTheme);

What I'd prefer is to have the theme update automatically - I've tried making use of the UpdateWindow and RedrawWindow functions of the User32 API, but the window doesn't reload.

So the question is - How do I "redraw" Visual Studio after changing the CurrentTheme property in the registry?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

ShellSettingsManager enables you to access and modify Visual Studio settings but only in the Windows registry. Any changes you make will not be picked up by Visual Studio until it is restarted because VS reads settings from the registry only when it starts. So this is the wrong approach.

To both change settings and apply them without requiring a restart, you will have to use DTE2.Properties as discussed in here. The following code snippet shows all the settings that can be changed programmatically from the Environment/General page (this is where you can change the theme):

EnvDTE.Properties generalProps = dte2Obj.Properties["Environment", "General"];
for (int i = 1; i <= generalProps.Count; ++i)
{
    System.Diagnostics.Debug.WriteLine(
        generalProps.Item(i).Name + ": " + generalProps.Item(i).Value);
}

By default in VS2013, this code will produce the following output:

AnimationSpeed: 5
RichClientExperienceOptions: 65535
WindowMenuContainsNItems: 10
CloseButtonActiveTabOnly: True
UseTitleCaseOnMenu: False
AutoAdjustExperience: True
Animations: True
AutohidePinActiveTabOnly: False
ShowStatusBar: True
MRUListContainsNItems: 10

All of these settings can be changed and VS will immediately apply the changes. The problem is that there is no property that enables you to change the theme. That's why I think it cannot be done.

over 4 years ago · Santiago Trujillo Relatório

0

Here's the simplest way to do it:

Overview:

  1. Use the "Import & Export Settings" feature to create two files: DarkTheme.vssettings and LightTheme.vssettings
  2. Programmatically invoke the Tools.ImportandExportSettings command to import those files at the appropriate time.

Details:

To create the two settings files:

  1. Launch Visual Studio and set the theme to "Light" through the UI
  2. From the Tools menu select "Import and Export Settings..."
  3. In the wizard, select "Export selected environment settings" and click "Next"
  4. In the "Which settings do you want to export?" page, deselect everything except "Options/Fonts and Colors" and click "Next"
  5. Name this file "Light.vssettings" and save it in a known location.
  6. Repeat steps 1 through 5 for the "Dark" theme, naming the file "Dark.vssettings".

To import these files programmatically use DTE.ExecuteCommand with the "/import" parameter like this:

Add a reference to EnvDTE.dll if you don't have it already.

var dte = GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;
dte.ExecuteCommand("Tools.ImportandExportSettings", @"/import:""C:\yourpath\LightTheme.vssettings""");

I hope that helps.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda