0

I need to get the current wallpaper and display it in a picturebox. Now from what I understand, One of the ways to get the wallpaper is by doing the following:

RegistryKey UserWallpaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", false);

How would I go about converting this to an Image so that i can display it in a PictureBox?

Bodokh
  • 976
  • 4
  • 15
  • 34

3 Answers3

1

The answer can already be found in another post since the value of the registry key is a file path

Loading PictureBox Image from resource file with path (Part 3)

Community
  • 1
  • 1
  • pictureBox1.Image = Image.FromFile(UserWallpaper.ToString() + ".bmp"); did not work... I also tried without the bmp – Bodokh Feb 25 '14 at 22:50
1
// get the registry-key
RegistryKey wp = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", false);

// get the wallpaper filename
string sFileName = (string)wp.GetValue("Wallpaper");

// finally load the image into picture box
pictureBox1.Image = Image.FromFile(sFileName);
Stokke
  • 1,871
  • 2
  • 13
  • 18
  • Thanks! I did the same thing with ToString and it didnt work? But this works great! Much obliged! – Bodokh Feb 25 '14 at 22:59
  • Do you happen to know how I can get 2 different wallpapers If I am using a dual monitor display? – Bodokh Feb 25 '14 at 23:01
  • As far as I know you can't have two different wallpapers on a dual monitor display. I guess you could fake it though by merging the two different images into one, positioning them side by side in the appropriate resolution and then set the background to "Tile". I think they would then span across both displays, and you would seemingly have two separate pictures on the screens. – Stokke Feb 25 '14 at 23:15
0

Is this what you're looking for?

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", false);
string wallpaper = key.GetValue("Wallpaper").ToString();
PictureBox pbox = new PictureBox();
pbox.Image = new Bitmap(wallpaper);
this.Controls.Add(pbox);
Residualfail
  • 79
  • 1
  • 12