babalonas 0 Newbie Poster

I'm trying to make a code that changes the wallpaper in visual basic express, but it errors:

Imports System.IO
Imports System.Runtime.InteropServices

Public Class Form1
    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As String, ByVal fuWinIni As Integer) As Long

    Private Const SPI_SETDESKTOPWALLPAPER = 20
    Private Const SPIF_UPDATEINIFILE = 1
    Private Const SPIF_SENDWININICHANGE = 2

    Private _WallPaperPath As String

    Public Property WallPaperPath()
        Get
            Return _WallPaperPath
        End Get
        Set(ByVal Value)
            _WallPaperPath = Value
        End Set
    End Property

    Public Sub ChangeWallPaper()
        If File.Exists(_WallPaperPath) = True Then
            SystemParametersInfo(SPI_SETDESKTOPWALLPAPER, 0, _WallPaperPath, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
        Else
   [B]  --->   Throw New FileNotFoundException("My.Resources.ord.jpg")[/B]
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ChangeWallPaper()
    End Sub
End Class

I have made the part that errors bold. It tells me to check if the file exist. I use .net

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.