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

编程入门 行业动态 更新时间:2024-10-21 13:24:45
本文介绍了更改“颜色主题";在Visual Studio扩展中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用C#编写Visual Studio扩展,希望它可以根据一天中的时间更改颜色主题(日落之后将应用深色主题-日出时将根据需要应用蓝色/浅色主题,具体取决于用户的偏好).

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).

我可以使用ShellSettingsManager对象公开的WriteableSettingsStore更改颜色主题.当我执行以下代码时,主题将在重新启动Visual Studio之后发生变化.

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

我希望自动更新主题-我尝试使用User32 API的UpdateWindow和RedrawWindow函数,但是不会重新加载窗口.

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.

问题是-更改注册表中的CurrentTheme属性后,如何重绘" Visual Studio?

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

推荐答案

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.

更多推荐

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

本文发布于:2023-11-13 14:36:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   主题   quot   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!