3
A
回答
4
'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)
1
1
試試這個程序:
Imports System
Imports System.Runtime.InteropServices
Public Class Desktop
Public Shared SPI_SETDESKTOPWALLPAPER As Integer = 20
Public Shared SPIF_UPDATEINIFILE As Integer = 1
Public Shared SPIF_SENDWININICHANGE As Integer = 2
Public Shared Sub Main(ByVal args() As String)
If (args.Length = 1) Then
SystemParametersInfo(SPI_SETDESKTOPWALLPAPER, 0, args(0), _
(SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE))
End If
End Sub
Private Declare Sub SystemParametersInfo Lib "User32.dll" (ByVal action As Integer, _
ByVal iparam As Integer, ByVal vparam As String, ByVal option As Integer)
End Class
1
您可以使用Win32
'user32
'更改桌面背景。 你需要聲明USER32 PI功能SystemParametersInfo
像爲:
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
,並調用這個函數與有效參數
,你也可以檢查這個環節,這是學習如何更改桌面背景的好文章vb.net
http://www.authorcode.com/how-to-set-desktop-background-in-vb-net/
0
這是一個簡單而實用的代碼,設置桌面只用一個定時器
Public Class Form1
Dim Location As String
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
Private Const SETDESKWALLPAPER = 20
Private Const UPDATEINIFILE = &H1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Location = ("image directory.jpg")
PictureBox1.BackgroundImage = Image.FromFile("C:\Users\Danny\Desktop\Hacker.jpg")
PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
SystemParametersInfo(SETDESKWALLPAPER, 0, Location, UPDATEINIFILE)
End Sub End Class
相關問題
- 1. Python - 快速更改桌面背景
- 2. 更改桌面背景與Python
- 3. 更改桌面背景mac os x
- 4. 如何使用VC++更改桌面背景
- 5. 使用WinRT for Windows RT更改桌面背景
- 6. Powershell - 使桌面背景更改立即生效
- 7. 使用jQuery更改頁面的背景
- 8. 在桌面背景上只顯示桌面背景上的winform
- 9. 如何用python更改我的桌面背景?
- 10. 更改桌子上的背景?
- 11. 如何隱藏Windows桌面並更改c#中的桌面背景顏色?
- 12. 更改頁面背景。 LocalStorage
- 13. VB.NET:更改背景不透明度
- 14. 使用javascript更改背景
- 15. mac osx css桌面背景
- 16. 繪製桌面背景(WIN32)
- 17. 如何更改桌面背景的顏色
- 18. 以編程方式更改桌面背景
- 19. 如何更改桌面或平板電腦上的StatusBar背景?
- 20. 更改OS X桌面背景圖像縮放模式
- 21. 更改不帶註冊表的桌面背景
- 22. 通過python在windows 10中更改桌面背景
- 23. 如何通過powercfg使用Python更改桌面背景設置幻燈片?
- 24. 使用Java本機訪問更改MAC系統的桌面背景
- 25. 用戶界面(如何更改背景)
- 26. 用JavaScript設置桌面背景圖片
- 27. 更改背景
- 28. 更改背景
- 29. 以用戶身份運行cronjob以更改Ubuntu中的桌面背景
- 30. 用javascript更改DIV背景
您是否在http://www.devasp.net/net/articles/display/421.html上發佈了此項[以編程方式更改桌面牆紙]? –
@astander - 如果他做了,它會有所作爲嗎? –
也許只是一點點X-) –