Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Namespace WindowsFormsApplication2
Public Partial Class Form1
Inherits Form
Const SPI_SETDESKWALLPAPER As Integer = 20
Const SPIF_UPDATEINIFILE As Integer = &H1
Const SPIF_SENDWININICHANGE As Integer = &H2
Public Sub New()
InitializeComponent()
End Sub
<DllImport("user32.dll", CharSet := CharSet.Auto)> _
Private Shared Function SystemParametersInfo(uAction As Integer, uParam As Integer, lpvParam As String, fuWinIni As Integer) As Integer
End Function
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.click
If textBox1.Text.Trim() = "" Then
MessageBox.Show("write something")
Return
End If
Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
Dim wallPaperPath As String = DirectCast(key.GetValue("Wallpaper", ""), String)
Dim im As Image = Image.FromFile(wallPaperPath)
Using gr As Graphics = Graphics.FromImage(im)
gr.DrawString(textBox1.Text, New Font("Arial", 50, FontStyle.Bold), Brushes.White, im.Width - textBox1.Text.Length * 30, 5)
End Using
Dim FolderPath As String = "c://New Wallpapers"
Dim imgPath As String = "c://New Wallpapers/img.jpg"
If Not System.IO.Directory.Exists(FolderPath) Then
System.IO.Directory.CreateDirectory(FolderPath)
End If
im.Save(imgPath)
key.SetValue("Wallpaper", imgPath)
key.SetValue("WallpaperStyle", 2.ToString())
key.SetValue("TileWallpaper", 0.ToString())
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imgPath, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub
End Class
End Namespace