且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改“颜色主题";在Visual Studio扩展中

更新时间:2023-01-27 11:30:42

ShellSettingsManager使您只能在Windows注册表中访问和修改Visual Studio设置.在重新启动之前,Visual Studio将不会对您进行的任何更改,因为VS仅在启动时才从注册表中读取设置.所以这是错误的方法.

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.

要更改设置并应用它们而无需重新启动,则必须使用 DTE2.Properties ,如此处中所述.以下代码段显示了可以在环境/常规"页面(可以在其中更改主题)中以编程方式更改的所有设置:

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);
}

在VS2013中,默认情况下,此代码将产生以下输出:

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

所有这些设置都可以更改,VS会立即应用更改.问题在于,没有可用于更改主题的属性.这就是为什么我认为无法完成的原因.

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.