コード例 #1
0
        public static bool Set(Image image, Wallpaper.Style style)
        {
            bool result = false;

            try
            {
                string text = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
                image.Save(text, ImageFormat.Bmp);
                RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
                switch (style)
                {
                case Wallpaper.Style.Centered:
                    registryKey.SetValue("WallpaperStyle", 1.ToString());
                    registryKey.SetValue("TileWallpaper", 0.ToString());
                    goto IL_BF;

                case Wallpaper.Style.Stretched:
                    registryKey.SetValue("WallpaperStyle", 2.ToString());
                    registryKey.SetValue("TileWallpaper", 0.ToString());
                    goto IL_BF;
                }
                registryKey.SetValue("WallpaperStyle", 1.ToString());
                registryKey.SetValue("TileWallpaper", 1.ToString());
IL_BF:
                Wallpaper.SystemParametersInfo(Wallpaper.SPI_SETDESKWALLPAPER, 0u, text, Wallpaper.SPIF_UPDATEINIFILE | Wallpaper.SPIF_SENDWININICHANGE);
                result = true;
            }
            catch
            {
            }
            return(result);
        }
コード例 #2
0
        public static bool Set(string filePath, Wallpaper.Style style)
        {
            bool result = false;

            try
            {
                Wallpaper.Set(Image.FromFile(Path.GetFullPath(filePath)), style);
                result = true;
            }
            catch
            {
            }
            return(result);
        }