/// <summary> /// Return the number of screens /// </summary> /// <returns>Count of screens based on the wallpaper mode</returns> internal static int GetScreenCount(MultiMonitorModes vMultiMonitorMode, WallpaperModes vWallpaperMode) { int screenCount;// = Screen.AllScreens.Length; //set the screen count default if (vMultiMonitorMode == MultiMonitorModes.DifferentOnAll && vWallpaperMode != WallpaperModes.Tile) { screenCount = Screen.AllScreens.Length; } else { screenCount = 1; // modify screen count in these specific circumstances switch (vWallpaperMode) { case WallpaperModes.None: break; case WallpaperModes.Centre: break; case WallpaperModes.FillWidth: break; case WallpaperModes.FillHeight: break; case WallpaperModes.Stretch: break; case WallpaperModes.Tile: //screenCount = 1; //screenCount = Screen.AllScreens.Length; break; case WallpaperModes.Span: //screenCount = 1; screenCount = Screen.AllScreens.Length; // Screen.AllScreens.Length; break; case WallpaperModes.LAWC: screenCount = Screen.AllScreens.Length; break; default: break; } } return(screenCount); }
/// <summary> /// NOTES: https://code.msdn.microsoft.com/windowsapps/CSSetDesktopWallpaper-2107409c /// https://stackoverflow.com/questions/1061678/change-desktop-wallpaper-using-code-in-net /// </summary> /// <param name="filename"></param> /// <param name="style"></param> /// <returns></returns> internal static Boolean SetWallpaper(string filename, WallpaperModes style) { Boolean output;// = false; RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); switch (style) { case WallpaperModes.Tile: //key.SetValue(@"WallpaperStyle", "0"); //key.SetValue(@"TileWallpaper", "1"); key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "1"); //output = true; break; case WallpaperModes.Centre: key.SetValue(@"WallpaperStyle", "0"); key.SetValue(@"TileWallpaper", "0"); //output = true; break; case WallpaperModes.Stretch: key.SetValue(@"WallpaperStyle", "2"); key.SetValue(@"TileWallpaper", "0"); //output = true; break; case WallpaperModes.FillWidth: key.SetValue(@"WallpaperStyle", "10"); //1 key.SetValue(@"TileWallpaper", "0"); //output = true; break; case WallpaperModes.FillHeight: key.SetValue(@"WallpaperStyle", "6"); key.SetValue(@"TileWallpaper", "0"); //output = true; break; case WallpaperModes.Span: key.SetValue(@"WallpaperStyle", "22"); key.SetValue(@"TileWallpaper", "1"); //output = true; break; //Same as SPAN, but just for custom building of the wallpaper (in other parts of the code) case WallpaperModes.LAWC: key.SetValue(@"WallpaperStyle", "22"); key.SetValue(@"TileWallpaper", "1"); //output = true; break; default: //output = false; break; } //WORKS, but black screens occasionally: //output = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); //output = NativeMethods.SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); output = NativeMethods.SystemParametersInfo(0x0014, 0, filename, 0x0001); //int result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); //output = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, 0); // 0 = dont save changes to theme https://stackoverflow.com/questions/35716843/how-to-restore-undo-desktop-wallpaper-after-changing //output = Convert.ToBoolean(result); //if (Convert.ToBoolean(result) == false) //{ // MessageBox.Show("ERROR WARNING WARNING WARNING!!!!"); //} if (output == false) { MessageBox.Show("There was an error setting the wallpaper.", "Error Setting Wallpaper", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(output); }