Results 1 to 4 of 4

Thread: Saving background image settings

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    9

    Saving background image settings


    Last edited by billgate128; Mar 13th, 2010 at 04:26 AM.

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Saving background image settings

    Hi Billgate, welcome to the forum. This is a fast-moving forum so messages sometimes slip off the front page rather quickly.

    You need to look at Settings. Right click on the project name in Solution Explorer and select Properties from the menu. Then click the Settings tab. Now add a setting to the table. Fill in a name (e.g. FormBackground), the type =String, scope = User, and the path/filename of an image file (e.g. C:\Pictures\Sky.jpg).

    Now you can code your form's Load event sub.
    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.BackgroundImage = Image.FromFile(My.Settings.FormBackground)
        End Sub
    Finally, add this line to the MouseClick sub:
    Code:
    My.Settings.FormBackground = image file
    and fill in the path and filename of the chosen background image.

    bye, BB

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Saving background image settings

    One point to note about boops' solution is that it relies on the image file being in the same place next time you start up. If you don't want to rely on the user not moving or deleting the file, you might want to copy it to the Application Data folder and then access it from there. This is what Windows does with wallpaper.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    22

    Re: Saving background image settings

    Quote Originally Posted by jmcilhinney View Post
    One point to note about boops' solution is that it relies on the image file being in the same place next time you start up. If you don't want to rely on the user not moving or deleting the file, you might want to copy it to the Application Data folder and then access it from there. This is what Windows does with wallpaper.
    Good call!
    Also you might want to add an IF THEN statement to.
    I did this for a program I wrote so that the user can select their own picture and if it is deleted, to VB meaning non existent then it will use it's default background.

    Here is a snippet:
    Code:
            On Error GoTo erbg
            If My.Settings.SaveBG = Nothing Then GoTo vend Else GoTo gb
            GoTo vend
    erbg:
            MsgBox("Your personal backround picture has either changed or has been moved. The default background will be used.", , "Error getting background picture.")
            GoTo vend
    
    gb:
            Me.BackgroundImage = Image.FromFile(My.Settings.SaveBG)
    vend:
    
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width