I am trying to set a background image of a form dynamically (on the button's click event).
When I stop the deployment of an application and restart to deploy it, background image of a form is removed.
I know the background image will remains the same till the application is not stopped.
But, I want to set it permanently, like we set using resources or we set using background image property of the form or any other control.
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If vbOK = FolderBrowserDialog2.ShowDialog() Then
TextBox1.Text = FolderBrowserDialog2.SelectedPath
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim id As String = "bg"
Dim folder As String = TextBox1.Text
If TextBox1.Text = "" Then
MsgBox("Please Select Image Path.", MsgBoxStyle.Information, "Message")
Else
Dim filename As String = System.IO.Path.Combine(folder, id & ".jpg")
Form1.BackgroundImage = Image.FromFile(filename)
End If
End Sub
And please note that the "bg" is the name of an image.
I know this code is the bad, and I am trying to improve it.
But, here my aim is to set a background image dynamically.
How to do it?