Click here to Skip to main content
6,594,932 members and growing! (15,313 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » General     Intermediate

Desktop Decorator : Changing your wallpaper the easy way in .NET

By Steve Dunn

An article describing how to change the wallpaper using .NET and C#
C#, Windows, .NET, Visual Studio, Dev
Posted:18 Apr 2004
Views:61,460
Bookmarked:26 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
15 votes for this article.
Popularity: 4.64 Rating: 3.94 out of 5
2 votes, 13.3%
1

2
3 votes, 20.0%
3
3 votes, 20.0%
4
7 votes, 46.7%
5

Introduction

This small article describes how to set the desktop wallpaper. There's really not much to it. The sample application is a Windows Forms application and uses the "Wallpaper" class to set the wallpaper. The class can set wallpaper from most image sources, including images stored locally or on the network/internet. To use the sample application, run it, select an image, and click the Apply button. To test the URL loading, try selecting an image from a web-page, for example, http://hp.msn.com/global/c/lg/msft_118x35.gif

Using the code

The class for setting the desktop wallpaper is named, not surprisingly, "Wallpaper". It contains one public method name 'Set'. This takes two parameters, a URI that points to the image you want to use, and a "Style" enumeration that specifies how you want the image displayed (tiled, centered, or stretched).

public sealed class Wallpaper 
{
 ...
  public enum Style : int 
  { 
   Tiled, 
   Centered, 
   Stretched 
  } 

  public static void Set ( Uri uri, Style style ) 
  {
    ...
  } 
}

Points of Interest

The class first saves your image to a temporary file using a Windows Bitmap format. This allows you to pass other image formats, such as a gif and jpeg files and have them automatically converted and used as wallpaper images. The class also allows source images from almost any location. A URI is passed which describes where the image is located. Feel free to use this code however you please. The usual stuff: if it buggers up your machine/life etc. then it's not my fault!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Steve Dunn


Member
I was born at a very young age. My hobbies include reading pornography and killing squirrels.
Occupation: Web Developer
Location: United States United States

Other popular .NET Framework articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
GeneralHow change html file to wallpaper? PinmemberDimaNikolaevich8:18 7 Aug '06  
Generalhow can i get current wallpaper,not use regedit info? Pinmemberargoli17:02 19 Mar '05  
GeneralA little sugestion with Centered Pinmemberwhitesnake17:54 6 Feb '05  
GeneralProxies and thanks PinsitebuilderPaul Watson8:53 20 Aug '04  
GeneralRestore original wallpaper PinmemberAntonio Barros5:24 22 Apr '04  
GeneralRe: Restore original wallpaper PinmemberS0k4r0:53 14 Dec '04  
GeneralI looked at this method too PinmemberNathan Blomquist7:05 19 Apr '04  
GeneralRe: I looked at this method too PinmemberJason Henderson4:33 20 Apr '04  
GeneralRe: I looked at this method too PinmemberNathan Blomquist6:17 20 Apr '04  
GeneralGood Hobbies PinmemberNorm Almond2:59 19 Apr '04  
GeneralRe: Good Hobbies PinmemberUncle Monkey3:50 19 Apr '04  
GeneralRe: Good Hobbies Pinmemberhxxbin5:59 23 Apr '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Apr 2004
Editor: Nishant Sivakumar
Copyright 2004 by Steve Dunn
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project