Fork me on GitHub

window桌面背景图片

通过修改注册表项:

\HKEY_CURRENT_USER\Control Panel\Desktop下的几个值,及可以将我们想要的图片设置成桌面的背景图

TileWallpaper   WallpaperStyle  Wallpaper

系统中默认的WallpaperStyle  =10

  TileWallpaper              WallpaperStyle 效果
居中 0    0   

 

平铺 1 0  
拉伸 0 2  

0 0 的效果

 

 1 0

 

 0 1

 

 

上代码

 private void SettWallPapper(String filePath)
        {
            using (RegistryKey desktopKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true))
            {

                //赋值
                //注意:在把数值型的数据赋到注册表里面的时候,
                //如果不加引号,则该键值会成为“REG_DWORD”型;
                //如果加上引号,则该键值会成为“REG_SZ”型。
                desktopKey.SetValue("TileWallpaper", "0");
                desktopKey.SetValue("WallpaperStyle", "0");
                desktopKey.SetValue("Wallpaper", filePath);
            }

            SystemParametersInfo(20, 1, filePath, 1);
        }

        [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
        public static extern int SystemParametersInfo(
            int uAction,
            int uParam,
            string lpvParam,
            int fuWinIni
            );

 

posted @ 2022-04-18 23:36  黄高林  阅读(406)  评论(0编辑  收藏  举报