private void buttonSelectFolder_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { Wallpaper.selectedFolderPath = folderBrowserDialog1.SelectedPath; string[] fileInfoJPG = Directory.GetFiles(Wallpaper.selectedFolderPath, "*.jpg", SearchOption.AllDirectories); string[] fileInfoPNG = Directory.GetFiles(Wallpaper.selectedFolderPath, "*.png", SearchOption.AllDirectories); if (fileInfoJPG.Length == 0 && fileInfoPNG.Length == 0) { MessageBox.Show("Please select a folder with PNG or JPG image(s) in it.", "ERROR", MessageBoxButtons.OK); Wallpaper.selectedFolderPath = null; return; } else { Settings.ChangeSetting(Settings.settings.wallpaperFolderDirectory, Wallpaper.selectedFolderPath); Wallpaper.fileInfoJPG = Directory.GetFiles(Wallpaper.selectedFolderPath, "*.jpg", SearchOption.AllDirectories); Wallpaper.fileInfoPNG = Directory.GetFiles(Wallpaper.selectedFolderPath, "*.png", SearchOption.AllDirectories); string path = Wallpaper.GetNewWallpaper(isShuffle.Checked); pictureBox1.Image = Image.FromFile(Wallpaper.wallpaperFile.FullName); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; if (path != null) { pictureBox1.LoadAsync(path); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Wallpaper.BurnNewWallpaper(Wallpaper.wallpaperFile.FullName), SPIF_UPDATEINIFILE); } } } }
private void timer1_Tick(object sender, EventArgs e) //Every minute. { timerCounter++; if (!String.IsNullOrEmpty(Settings.ReadSetting(Settings.settings.wallpaperFolderDirectory)) && !String.IsNullOrWhiteSpace(Settings.ReadSetting(Settings.settings.wallpaperFolderDirectory))) //Is wallpaperFolderDirectory selected && that selected directory is NullORWhiteSpace { SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Wallpaper.BurnNewWallpaper(Wallpaper.wallpaperFile.FullName), SPIF_UPDATEINIFILE); pictureBox1.LoadAsync(Wallpaper.wallpaperFile.FullName); if (timerCounter == Convert.ToInt32(numericWallpaperTime.Value)) //If it's time to get a new wallpaper. { timerCounter = 0; string path = Wallpaper.GetNewWallpaper(isShuffle.Checked); if (path != null) { pictureBox1.Image = Image.FromFile(Wallpaper.wallpaperFile.FullName); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; pictureBox1.LoadAsync(path); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Wallpaper.BurnNewWallpaper(Wallpaper.wallpaperFile.FullName), SPIF_UPDATEINIFILE); } } else if (timerCounter > Convert.ToInt32(numericWallpaperTime.Value)) //Stop timerCounter going over the max minutes. { timerCounter = 0; } } }