Using My.Settings and forms

  • Thread starter Thread starter Linus
  • Start date Start date
L

Linus

Hi,

I'm using My.Settings to save the state of controls in my form. The
data is read in from My.Settings in the New section in the form. The
problem is that I've got a Sub that catches all the changes in the
different controls and saves ALL control states to My.Settings. This
is to not have 30-40 different Subs handling every control
independently. So when a for example text is read in from My.Settings
and put into a textbox, every other control will be written to
My.Settings empty because they haven't had their data put into them
yet. I've fixed this by using a global boolean variable to state
wheter the program is in startup or not and if anything should be
written to My.Settings or not.
I'm wondering if there's a more elegant way to do this. I thought of
using My.Application.Startup and Shutdown but the form hasn't been
initialized yet or has been disposed of already.

Linus
 
Hi,

I'm using My.Settings to save the state of controls in my form. The
data is read in from My.Settings in the New section in the form. The
problem is that I've got a Sub that catches all the changes in the
different controls and saves ALL control states to My.Settings. This
is to not have 30-40 different Subs handling every control
independently. So when a for example text is read in from My.Settings
and put into a textbox, every other control will be written to
My.Settings empty because they haven't had their data put into them
yet. I've fixed this by using a global boolean variable to state
wheter the program is in startup or not and if anything should be
written to My.Settings or not.
I'm wondering if there's a more elegant way to do this. I thought of
using My.Application.Startup and Shutdown but the form hasn't been
initialized yet or has been disposed of already.

This has been discussed numerous times already, and from my
recollection, that was the most comment suggestion.

It's how I handle that situation.
 
Just to be clear, are you saying that every time a control's "main" property
changes (such as TextBox.Text) you're writing the value of every main
property of every control to My.Settings?

So if a user was typing away merrily into a textbox, every time they press a
key then all the controls on the form get their properties saved? If so,
I'd say the best way to fix it is to not do this at all, but instead to
handle OnClosed and save all the settings then - just once.

-Alex
 
I'm using the TextChanged event so I guess it is. I could probably
read the sender object that is passed on to the Sub and then use
If...Elseif...End If statement to just save that control to
My.Settings but it works for now without too much lag. I think I'll do
it once the controls exceed 50.

Linus
 
Sorry, I didn't read your last sentence. OnClosed seems to be what
I've been looking for. Thanks a lot!

Linus
 
Back
Top