使用.NET中的代码更改桌面壁纸
如何使用 C# 代码更改桌面壁纸?
How can I change the desktop wallpaper using C# Code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何使用 C# 代码更改桌面壁纸?
How can I change the desktop wallpaper using C# Code?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
这是从我一两年前编写的应用程序中提取的一个类:
我没有对其进行广泛的测试,因此使用时请自行承担风险。
Here's a class yanked from an app I wrote a year or two ago:
I haven't tested it extensively, so use at your own risk.
基于这个有用的答案,我还做了我自己的应用,用于设置与屏幕分辨率匹配的壁纸。
但注册表设置错误。 以下是正确的值(在 Win 7、Win 8.1、Win 10 上测试)。
Bases on this useful answer, I've also made my own app to set wallpaper matching screen resolution.
But the registry settings were wrong. Here are the correct values (tested on Win 7, Win 8.1, Win 10).
如果您想临时设置桌面壁纸而不污染 Windows 设置历史记录,这里是我提出的要点。
它会在设置之前备份壁纸历史记录(存储在注册表中)临时壁纸,之后您可以将其恢复。
https://gist.github.com/Drarig29/4aa001074826f7da69b5bb73a83ccd39
If you want to temporarily set a desktop wallpaper without polluting the Windows settings history, here is a gist I made.
It backups the wallpaper history (stored in the registry) before setting the temporary wallpaper and you can restore it back afterwards.
https://gist.github.com/Drarig29/4aa001074826f7da69b5bb73a83ccd39
如果您在 c# 中使用 UWP,这是我找到的代码 这里
其实我觉得还可以更简单
file.png是你的照片,可以是.jpg或其他格式
If you're using UWP in c# , here's the code I found here
Actually I think it can be more simple
file.png is your photo ,it can be .jpg or something else
调整 Neal N 对 Gif 的回答:
另请注意,您需要使用:
最后,右键单击您的项目,添加引用,然后(在程序集和框架中)添加Presentation Core、System.Xaml 和 WindowsBase。
然后右键单击您的项目并进入“属性”,并确保目标框架是.Net Framework 4.5。 如果更改此设置,您可能需要重新启动 Visual Studio。
Tweaking Neal N's answer for Gifs:
Also note that you need to use:
Finally, right click on your Project, Add Reference, and (in Assemblies and Framework) add Presentation Core, System.Xaml, and WindowsBase.
Then right click on your Project and go into Properties, and make sure Target Framework is .Net Framework 4.5. If you change this you may need to restart Visual Studio.