Tag: 壁纸

为什么这段代码会锁定我的文件?

我已经缩小到这个方法,但我不明白为什么它锁定文件。 我相信你可以用类似的东西 using( something) { //do stuff here } 但我不确定A)是否会解决问题,或者B)如果确实如此,那就是正确的方法。 有任何想法吗? [DllImport(“user32.dll”, CharSet = CharSet.Auto)]private static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, String vParam, UInt32 winIni); private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14; private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01; private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02; private void SetWallpaper(string path) { try { Image […]

C#:将桌面墙纸设置为纯色

我正在使用此代码删除当前壁纸并设置纯色: public static class WallpaperColorChanger { public static void SetColor(Color color) { // Remove the current wallpaper NativeMethods.SystemParametersInfo( NativeMethods.SPI_SETDESKWALLPAPER, 0, “”, NativeMethods.SPIF_UPDATEINIFILE | NativeMethods.SPIF_SENDWININICHANGE); // Set the new desktop solid color for the current session int[] elements = { NativeMethods.COLOR_DESKTOP }; int[] colors = { System.Drawing.ColorTranslator.ToWin32(color) }; NativeMethods.SetSysColors(elements.Length, elements, colors); // Save value in registry […]

如何以编程方式更改Windows桌面墙纸?

我希望使用C#为Windows XP设置壁纸。 我已经开发了代码,因此它在Windows 7中完美运行,但显然它与XP不同。 我将壁纸添加为资源,将其编译操作设置为内容并始终复制。 奇怪的是,它在桌面属性对话框中设置了正确的墙纸名称。 但是,壁纸未设置。 我的代码如下所示: public sealed class Wallpaper { Wallpaper() { } const int SPI_SETDESKWALLPAPER = 20; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDWININICHANGE = 0x02; [DllImport(“user32.dll”, CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); public enum Style : int { Tiled, Centered, Stretched […]