Wallpaper issue

RajanPanchal's Avatar, Join Date: Jul 2008
Newbie Member
How do I set wallpaper using Visual basic?
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~

Code: vb.net
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging

Public Class frmMain
    Inherits System.Windows.Forms.Form
'api to set the systems parameters for changing the wallpaper
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

    'constants to be used with the above api
        Private Const SPI_SETDESKWALLPAPER = 20
        Private Const SPIF_UPDATEINIFILE = &H1

Private Sub btnSetWallpaper_Click(ByVal sender As System.Object, ByVal e As         
                  System.EventArgs) Handles btnSetWallpaper.Click

        'just some generic path and name for the image in the picturebox to save to
        Dim imagePath As String = Application.StartupPath & "\myNewWallpaper.bmp"

        pic.Image.Save(imagePath, ImageFormat.Bmp)

        'set the parameters to change the wallpaper to the image you selected
        SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)

    End Sub

 Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)             
          Handles btnBrowse.Click

         'select a image and get the path
        Dim dlg As OpenFileDialog = New OpenFileDialog

        dlg.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp;*.gif;*.jpg"
        dlg.Title = "Select the image to load."


        'put the selected image in the picturebox to see it
        pic.Image = Image.FromFile(dlg.FileName)

    End Sub
End class