Is it possible to change desktop background using VB.NET?
I'd like to change the icons too?
I plan on making a VB.NET program that can automatically make Windows XP look like Mac in just one click.
Steps you will do. Start visual studio 2005 and create a new window project. Set the following properties of the form
'Text = "Set Wallpaper"
'Size = “1024,750”
Now drip a picture box control on the form and set its following properties.
'Size = “1024,725”
'Sizemode = ”centerimage”
Drop a two button controls on the form and set its following properties as below.
'First button control.
'Name = " btgetimage"
'Text = " Brows For Image"
'Second button control.
'Name = " btsetwallpaper"
'Text = " Set Wallpaper"
Now drop an openfiledialog control on the form. Open you code window and import the following namespace.
Imports System.IO.Directory
Now declare the function and variables as below which will use win API's to set the wallpaper.
Private Const SPI_SETDESKWALLPAPER As Integer = &H14
Private Const SPIF_UPDATEINIFILE As Integer = &H1
Private Const SPIF_SENDWININICHANGE As Integer = &H2
Private Declare Auto Function SystemParametersInfo Lib "user32.dll" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
Const WallpaperFile As String = "c:\wallpaper.bmp"
Make a function as below.
Friend Sub SetWallpaper(ByVal img As Image)
Dim imageLocation As String
imageLocation = My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.MyPictures, WallpaperFile)
Try
img.Save(imageLocation, System.Drawing.Imaging.ImageFormat.Bmp)
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imageLocation, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
Catch Ex As Exception
MsgBox("There was an error setting the wallpaper: " & Ex.Message)
End Try
End Sub
Now in the click event of the first button write the following code to open and get the image.
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "JPG|*.jpg|Bitmap|*.bmp"
Dim dialogresult As DialogResult = OpenFileDialog1.ShowDialog
If dialogresult = Windows.Forms.DialogResult.OK Then
PictureBox1.ImageLocation = OpenFileDialog1.FileName
btsetwallpaper.Enabled = True
End If
In the click event of the second button write following code to set the wallpaper.
SetWallpaper(Me.PictureBox1.Image)
MessageBox.Show("Wallpaper has been changed", "Set Wallpaper", MessageBoxButtons.OK, MessageBoxIcon.Information)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With