Results 1 to 4 of 4

Thread: Saving background image on exit

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    3

    Saving background image on exit

    In my project, I have a form that changes the background image of the main form and others forms that will be selected to be change. The images I used was from the resources.

    My problem is, when I exit the application and run it again, the images were back again to default. The changes I made has not saved. Please help me fix this.

    This is my code. Please help me fix it.

    Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApply.Click
    If cmbBackground.Text = "Default" Then
    frmMain.BackgroundImage = My.Resources.windows_8_fish
    frmLogIn.BackColor = Color.DarkGreen
    frmManageAccount.BackgroundImage = My.Resources.waves
    frmAbout.BackgroundImage = My.Resources.waves
    frmTermsandCondition.BackgroundImage = My.Resources.waves
    frmGmail.BackgroundImage = My.Resources.waves
    frmHotmail.BackgroundImage = My.Resources.waves
    frmYahoo.BackgroundImage = My.Resources.waves
    End If

    If cmbBackground.Text = "Alien Telescope" Then
    frmMain.BackgroundImage = My.Resources.alien_telescope
    End If
    If rbApplyAll.Checked = True Then
    frmLogIn.BackgroundImage = My.Resources.alien_telescope
    frmManageAccount.BackgroundImage = My.Resources.alien_telescope
    frmAbout.BackgroundImage = My.Resources.alien_telescope
    frmTermsandCondition.BackgroundImage = My.Resources.alien_telescope
    frmGmail.BackgroundImage = My.Resources.alien_telescope
    End If
    If chkAbout.Checked = True Then
    frmAbout.BackgroundImage = My.Resources.alien_telescope
    frmTermsandCondition.BackgroundImage = My.Resources.alien_telescope
    ElseIf chkGmail.Checked = True Then
    frmGmail.BackgroundImage = My.Resources.alien_telescope
    ElseIf chkLogin.Checked = True Then
    frmLogIn.BackgroundImage = My.Resources.alien_telescope
    ElseIf chkManageAccount.Checked = True Then
    frmManageAccount.BackgroundImage = My.Resources.alien_telescope
    End If
    End Sub

  2. #2
    New Member
    Join Date
    Aug 12
    Posts
    3

    Re: Please help on saving the images

    Please help me VB.net experts. We are going to pass this project on saturday.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,545

    Re: Saving background image on exit

    Sounds like a job for Application Settings

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 06
    Location
    Providence, RI - USA
    Posts
    9,167

    Re: Saving background image on exit

    1. Create a user scope setting of type string for each form that you want to save the background image setting. This setting will store the name of the resource, i.e "alien_telescope", "windows_8_fish"...
    Set the setting's default value to the name of the default resource you use.
    2. In form load, you read this setting and use resourcemanager to retrieve the resource with that name. For example:
    Code:
    frmMain.BackgroundImage = CType(My.Resources.ResourceManager.GetObject(My.Settings.frmMainBgImageResourceName), Image)
    3. When the user change the form background image, you save the selected resource name back to My.Settings
    Code:
    If cmbBackground.Text = "Alien Telescope" Then
        frmMain.BackgroundImage = My.Resources.alien_telescope
        My.Settings.frmMainBgImageResourceName = "alien_telescope"
    End If
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

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