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.
Quote:
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
Re: Please help on saving the images
Please help me VB.net experts. We are going to pass this project on saturday.
Re: Saving background image on exit
Sounds like a job for Application Settings
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