Wallpaper issue

Discussion in 'Visual Basic ( VB )' started by RajanPanchal, Jul 8, 2008.

  1. RajanPanchal

    RajanPanchal New Member

    Joined:
    Jul 2, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    How do I set wallpaper using Visual basic?
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    In VB.NET :

    Code:
    
    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."
    
            dlg.ShowDialog()
    
            'put the selected image in the picturebox to see it
            pic.Image = Image.FromFile(dlg.FileName)
            dlg.Dispose()
    
        End Sub
    End class
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice