0

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?

Paul Karam
  • 4,052
  • 8
  • 30
  • 53
Umesh
  • 71
  • 3
  • 14
  • Simply use a config file to save the last used image or use the My.Settings – Mederic Jun 19 '17 at 12:27
  • Possible duplicate of [VB.Net How do I read/write custom config file](https://stackoverflow.com/questions/4616962/vb-net-how-do-i-read-write-custom-config-file) – Mederic Jun 19 '17 at 12:30
  • may be, possible duplicate, but I can't understand anything in the link given above, it's hard to understand for me, I don't know how to use that link to achieve my target, because I am just a beginner. So, please suggest me anything else or please explain it. thanks for the reply. – Umesh Jun 19 '17 at 12:51
  • the solution in the link is three lines if you can't understand three lines then you should go and read the basics of vb.net: `My.Settings.FirstName = "Chris" Dim F = My.Settings.FirstName My.Settings.Save()` – Mederic Jun 19 '17 at 12:56
  • yeah, I can't understand the meanings of that three lines, but I will. Thanks for the explanation. – Umesh Jun 19 '17 at 13:07
  • then you should read basics of vb.net because the only thing there is to is declaring a variable and calling a method. If you don't know how to create a variable you shouldn't ask more complex questions. – Mederic Jun 19 '17 at 13:13
  • Possible duplicate of [How to save a Forms Background Image using My.Settings.Save Visual Basic](https://stackoverflow.com/questions/37008278/how-to-save-a-forms-background-image-using-my-settings-save-visual-basic) – Knowledge Cube Jun 19 '17 at 13:13
  • Google also pulls up [this forum link](https://www.codeproject.com/Questions/575140/SaveplusformplusbackgroundplusimageplustoplusMy-Se), which you may find useful. – Knowledge Cube Jun 19 '17 at 13:15

0 Answers0