Membuat Program Set Wallpaper dengan vb.net 2008
Hai Sob , kali ini saya akan membahas tentang
bagaimana cara membuat program set wallpaper .
1.
Pertama-tama , buka terlebih
dahulu microsoft visual basic (Di sini saya menggunakan Microsoft Visual Basic
2008/VB.NET)
2.
Lalu klik creat project =>
pilih windows form application => berinama suka-suka => enter
3.
Setelah itu , tambahkan :
-
2 buah button
-
1 buah picturebox
-
1 buah combobox
-
1 buah openfiledialog
Lalu atus posisinya sesuka hati
4.
Atur properties sebagai berikut :
Button1
|
Name : caributton
|
Text : Search
|
|
Button2
|
Name : Aturbutton
|
Text : Set
|
|
Combobox1
|
Name : StyleCBox
|
Picturebox1
|
Name : Pic_View
|
5. Klik kanan pada form lalu pilih view code
6. Hapus semua kode dan paste-kan kode berikut :
Imports System
Imports
System.Runtime.InteropServices
Imports
System.Drawing
Imports
Microsoft.Win32
Imports
System.StackOverflowException
PublicClass Wallpaper
Const
SPI_SETDESKWALLPAPER AsInteger = 20
Const
SPIF_UPDATEINIFILE AsInteger = &H1&
Const
SPIF_SENDWININICHANGE AsInteger = &H2&
<DllImport("user32")>
_
PublicSharedFunction
SystemParametersInfo(ByVal uAction AsInteger, _
ByVal uParam AsInteger, ByVal
lpvParam AsString, ByVal
fuWinIni AsInteger) AsInteger
EndFunction
PublicEnum Style AsInteger
Tiled
Centered
Stretched
EndEnum
PublicSub
SetWallpaper(ByVal path AsString, ByVal selectedStyle As Style)
Dim key As RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
SelectCase
selectedStyle
Case
Style.Stretched
key.SetValue("WallpaperStyle",
"2")
key.SetValue("TileWallpaper",
"0")
Case
Style.Centered
key.SetValue("WallpaperStyle",
"1")
key.SetValue("TileWallpaper",
"0")
Case
Style.Tiled
key.SetValue("WallpaperStyle",
"1")
key.SetValue("TileWallpaper",
"1")
EndSelect
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
EndSub
Dim Nama_File AsString
PrivateSub
Wallpaper_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) HandlesMyBase.Load
'
OpenFileDialog1.ShowDialog()
'
OpenFileDialog1.Filter = "JPG|*.jpg|Bitmap|*.bmp"
'
OpenFileDialog1.InitialDirectory = "%SystemRoot%"
styleCBox.DataSource = System.Enum.GetNames(GetType(Wallpaper.Style))
EndSub
PrivateSub
cariButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
cariButton.Click
If
DialogResult.OK = OpenFileDialog1.ShowDialog() Then
Nama_File = OpenFileDialog1.FileName
Pic_View.Image = New Bitmap(Nama_File)
EndIf
EndSub
PrivateSub
AturButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
AturButton.Click
Dim w As Wallpaper = New
Wallpaper()
w.SetWallpaper(Nama_File, CType(System.Enum.Parse(GetType(Wallpaper.Style), styleCBox.Text),
Wallpaper.Style))
SetWallpaper(Nama_File, CType(System.Enum.Parse(GetType(Wallpaper.Style), styleCBox.Text),
Wallpaper.Style))
EndSub
EndClass
Untuk Lebih Jelas Lihat Video Di Bawah ini
7. Setelah
itu , di run dengan menekan tombol F5
8. Ini
hasilnya
9.
Selamat mencoba ..
No comments:
Post a Comment