Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Wallpaper issue (http://www.go4expert.com/forums/wallpaper-issue-t11952/)

RajanPanchal 8Jul2008 17:08

Wallpaper issue
How do I set wallpaper using Visual basic?

SaswatPadhi 7May2009 20:03

Re: Wallpaper issue

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

All times are GMT +5.5. The time now is 19:34.