[RESOLVED] My.Settings not saving.
I'm new to the .NET way of VB...
I've setup some simple settings for a program i'm creating.
The settings pretty much just save the forms Left & Top positions.
After i setup the settings, i changed the "Root Namespace" and "Assembly Name".
Now, for some reason, when ever i save to my.settings, it won't save once the program has been closed. I've checked the "app.config" file and it seems to be all good.
Any way, checkout these screen shots: You may notice that the settings are strings in the app.config file, but in the project's properties they are integers. I originally set them as integers. I don't know why strings were put there.
http://img444.imageshack.us/img444/5...3461ip4.th.jpg
http://img444.imageshack.us/img444/6...3464wc6.th.jpg
Re: My.Settings not saving.
Dont worry about the serializeAs="String" tag, thats just the way it always "does".
If you want the location of the form to be set from the settings at startup and saved to the settings at shutdown, theres a simple way:
Create a setting of type System.Drawing.Point.
In the form properties, select (ApplicationSettings) and then (PropertyBinding).
In the dialog that appears, choose the Location property and select the newly created setting in the dropdownlist.
The forms Location property is now bound to the setting :)
Re: My.Settings not saving.
Oh, the forms position isn't the problem. That could be easily fixed.
But why doesn't the my.settings work?
Re: My.Settings not saving.
Please provide a list of steps that we can perform to reproduce the issue, starting with a new project.
Re: My.Settings not saving.
Umm, i've tried to replicate the problem... but have failed. Though this is not the first time it has happened and it's a completely new program i had started to make.
Any way, i've uploaded the project, perhaps you could find out why it's doing it, how to fix, or how to prevent.
http://www.megafileupload.com/en/fil...Timer-rar.html
In the mean time, i'm just going to start the program again and copy what i have already started. But i would still like to know how to fix this problem instead of running from it. Also on a side note, this problem has happened before, on one particular program i was making it would save Integer values, but it wouldn't save Strings. I had all the variable types set properly and that too.
Thank you =).
Re: My.Settings not saving.
OK, I got it to replicate the error, twice now:
This is what i did:
1. Create a new project
2. Copy all the controls from the old project (Using Ctrl+A, Ctrl+C)
3. Pasted All the controls (Ctrl+V)
4. Resized the form to fit the controls.
5. Changed the Form's MaximizeBox Property to False
6. Changed the Form's FormBorderStyle to FixedSingle
7. Renamed the form to "FrmMain"
8. Changed the forms filename to "FrmMain" (In Visual Basic of course).
9. Changed the Root Namespace and Assembly name to "Shutdown".
10. Went into settings and put in FrmMainX and FrmMainY and made them both as integers.
11. Pasted the following code into the form:
vb Code:
Private Sub CmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdExit.Click
My.Settings.FrmMainX = Me.Left
My.Settings.FrmMainY = Me.Top
Dim I As Integer
For I = 1000 To 1 Step -1
Me.Opacity = I / 100
Application.DoEvents()
Next
Me.Opacity = 0
Me.Hide()
End
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
CmdExit_Click(CmdExit, e)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Left = My.Settings.FrmMainX
Me.Top = My.Settings.FrmMainY
End Sub
12. Started it and closed the form, started it again and it was back at the default position.
By the way, It didn't matter if the Form1_Load and Form1_FormClosed subs were named FrmMain_Load and FrmMain_FormClosed. It still happens
Re: My.Settings not saving.
Adding in My.Settings.Save seems to fix this problem.
But it saves without My.Settings.Save Sometimes too! If no one has anything to say to this I'll mark the thread resolved.
Re: [RESOLVED] My.Settings not saving.
Have you set the StartPosition property of the form to Manual? If not then manually setting the Location will have no effect as the form will be shown initially where the StartPosition property tells it to be.