C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Change Desktop Wallpaper using VB.NET


Posted Date: 09 Jul 2008    Resource Type: Code Snippets    Category: VB.NET Syntax
Author: ranipriyaMember Level: Gold    
Rating: Points: 8



The following code sample changes the wallpaper of a desktop using VB.NET code.

The example code is that for a form that enables the user to pick a desired wallpaper from hard disk and set it as the wallpaper.


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





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Set Wallpaper using VB.NET  .  Set wallpaper using .NET  .  Set Desktop Wallpaper  .  Changing wallpaper  .  Change Wallpaper using VB.NET  .  Change Desktop Wallpaper  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Generate All Prime No. Between Given Number
Previous Resource: Get the Linecount from a Word file
Return to Discussion Resource Index
Post New Resource
Category: VB.NET Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use