Using My.Settings and forms

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
 
J

Joe Cool

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.
 
A

Alex Clark

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
 
L

Linus

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
 
L

Linus

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

Linus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top