How to make a Wallpaper Changer
Posted: Tue Dec 07, 2010 5:19 pm
Hello everyone,
As I said before while posting my Wallpaper Changer application that I will post a tutorial, I am posting it now. What you will learn in this tutorial is how to change the Desktop's wallpaper by using an application. Its pretty simple and short-length coding. So the tutorial will just as easy to follow. Please don't post any type of negative comments.
---------------------------------------------------------------------------
First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Wallpaper Changer and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.
First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Wallpaper Changer. Change it's StartPosition property to CenterScreen. Change it's FormBorderStyle to FixedSingle. Change it's MaximizeBox property to False.
Now add the following things to the form:
(1)_ 1 PictureBox. Change it's SizeMode property to StretchImage. Change it's BorderStyle property to FixedSingle.
(2)_ 2 Buttons. Change Button1's Text property to Browse... and Button2's Text property to Set Wallpaper.
Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.
Type the following code before Public Class Form1:
---------------------------------------------------------------------------
Voila! You have just completed making a Wallpaper Changer which sets the wallpaper of your desktop with the image that you choose. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.
And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.
Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making an Icon Extractor project myself so you can download the source file in the attachments.
Thank you.
![Image]()
As I said before while posting my Wallpaper Changer application that I will post a tutorial, I am posting it now. What you will learn in this tutorial is how to change the Desktop's wallpaper by using an application. Its pretty simple and short-length coding. So the tutorial will just as easy to follow. Please don't post any type of negative comments.
---------------------------------------------------------------------------
First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Wallpaper Changer and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.
First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Wallpaper Changer. Change it's StartPosition property to CenterScreen. Change it's FormBorderStyle to FixedSingle. Change it's MaximizeBox property to False.
Now add the following things to the form:
(1)_ 1 PictureBox. Change it's SizeMode property to StretchImage. Change it's BorderStyle property to FixedSingle.
(2)_ 2 Buttons. Change Button1's Text property to Browse... and Button2's Text property to Set Wallpaper.
Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.
Type the following code before Public Class Form1:
Code: Select all
Type the following code after Public Class Form1:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Code: Select all
Write the following code by double-clicking Button1 whose Text property was Browse...:
Inherits System.Windows.Forms.Form
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
Private Const SPI_SETDESKWALLPAPER = 20
Private Const SPIF_UPDATEINIFILE = &H1
Code: Select all
Write the following code by double-clicking Button2 whose Text property was Set Wallpaper:
Dim dlg As OpenFileDialog = New OpenFileDialog
dlg.Filter = "Image Files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png"
dlg.Title = "Select the image to load."
dlg.ShowDialog()
PictureBox1.Image = Image.FromFile(dlg.FileName)
dlg.Dispose()
Code: Select all
Well, that's all. It was real easy, wasn't it?Dim imagePath As String = Application.StartupPath & "\New Wallpaper.bmp"
PictureBox1.Image.Save(imagePath, ImageFormat.Bmp)
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)
---------------------------------------------------------------------------
Voila! You have just completed making a Wallpaper Changer which sets the wallpaper of your desktop with the image that you choose. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.
And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.
Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making an Icon Extractor project myself so you can download the source file in the attachments.
Thank you.
