anybody know how to upload or set piture into windows form using code..i want create a button like browse that can chnge background and every i relaunch application,bckground is still there..please anybody..

Edited by arezz09: n/a

5 Years
Discussion Span
Last Post by codeorder

See if this helps to save and load a image, then use it as BackgroundImage of a Form.

Public Class Form1
    Private myFile As String = "C:\test.txt" '// your file to save/load image path.
    Private myLoadedImageFile As String = "" '// used to store FullPath of image loaded.

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        IO.File.WriteAllText(myFile, myLoadedImageFile) '// Save FilePath of image.
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(myFile) Then '// check if file containing FullPath of image exists.
            If IO.File.Exists(IO.File.ReadAllText(myFile)) Then '// read file and check if image exists.
                myLoadedImageFile = IO.File.ReadAllText(myFile) '// store image.
                Me.BackgroundImage = Image.FromFile(myLoadedImageFile) '// change BackgroundImage.
            End If
        End If
        Me.Visible = True
        Dim ofd As New OpenFileDialog
        With ofd
            .Title = "Select a image to use as Background..."
            If .ShowDialog = DialogResult.OK Then
                myLoadedImageFile = .FileName '// store FullPath to use for when saving.
                Me.BackgroundImage = Image.FromFile(.FileName) '// add image as BackgroundIMage to Form.
            End If
        End With
    End Sub
End Class
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.