Example #1
0
 /// <summary>
 /// Sets a random image from the list as wallpaper
 /// </summary>
 private void SetRandomImage()
 {
     if (!string.IsNullOrEmpty(LastDir))
     {
         if (Images == null || Images.Count == 0)
         {
             ShowDebug("Populating empty image list");
             try
             {
                 GetImages(LastDir);
             }
             catch (Exception ex)
             {
                 ShowError(ex);
             }
             if (Images == null || Images.Count == 0)
             {
                 ShowWarning("Directory doesn't contanins any images. Timer stopped");
                 T.Stop();
             }
         }
         string ImageFile = PopRandom();
         if (!string.IsNullOrEmpty(ImageFile))
         {
             if (File.Exists(ImageFile))
             {
                 ShowDebug("Setting image");
                 try
                 {
                     DesktopWallpaper.Set(ImageFile, DesktopWallpaper.Style.Stretch);
                     Image I = Image.FromFile(ImageFile);
                     if (pbCurrent.Image != null)
                     {
                         pbCurrent.Image.Dispose();
                     }
                     pbCurrent.Image = I;
                     ShowDebug("Image set");
                 }
                 catch (Exception ex)
                 {
                     ShowError(ex);
                 }
             }
             else
             {
                 ShowInfo($"{ImageFile} from cache no longer exists");
             }
         }
         else
         {
             ShowWarning("Couldn't get image from directory. Timer stopped");
             T.Stop();
         }
         SaveSettings();
     }
     else
     {
         ShowDebug("Directory not yet selected, skipping wallpaper function");
     }
 }
Example #2
0
        static void Main(string[] args)
        {
            DesktopWallpaper wallpaper = new DesktopWallpaper();

            string imageLocation     = @"C:\Windows\Web\Wallpaper\Theme2\img11.jpg";
            uint   monitorCount      = wallpaper.GetMonitorDevicePathCount();
            string monitorDevicePath = wallpaper.GetMonitorDevicePathAt(1);

            wallpaper.SetWallpaper(monitorDevicePath, imageLocation);

            Console.Read();
        }