Check this Module out, if you understand it then you will use it (-:
Dear all,
i used to write a lot of code inside my forms inside the load event and in the closing event. i used to write this code because i wanted my software to remember last user settings. in other words i wanted the software to remeber for each form in the system where did you user positined last time, what item he was selecting in the listbox. which radio button selection, which tabpage is viewed in the tabcontrol , which last dates are selected in the datetime picker and other settings. i usually wanted the user to open the form exactly as the last time he closed it.
it was too hard and i did a lot of coding on each forms. i missed some controls on the hurry or i was too lazzy to write codes for them.
Moreover i used to save the settings in the registery, jmcilhinney and i was discussing in a thread and he pointed out that saving settings in the registery is a bad practice because it is considered now the bottleneck for performance in windows os. Moreover there was no easy way that my user can move his settings along on multiple pcs. (export and import registery keys is very pain in the face ).
so , i decided to write a module to do it for me, save all the possible settings regardless what controls are placed on the form and regardless if they are nested or not.
as a result of several hours of working today i managed to produce this class.
it is called formsettings
it has two public functions that developer would like to use
saveform and loadtoform
you can use it like this
VB Code:
'To save form settings
Dim x As New FormSettings
x.SaveForm(Me)
'to load settings into form
Dim x As New FormSettings
x.LoadtoForm(Me)
this class saves the settings into one xml file called "settings.xml", it is placed in the root directory of the application and can be moved to transfer settings between computers.
also i made some adjustements to the control,
1 - during the saving or loading process if you want to ignore a certain control on the form, just set its tag to "dontsave" in design or runtime.
My Class will ignore it on the sweep
2 - If you want to choose certain types of controls to be saved and loaded, you will have a set of public variables as following in the class
'''''''''''
'Setting Parameters
Public FormSize As Boolean = True
Public FormPosition As Boolean = True
Public ListBoxes As Boolean = True
Public ComboBoxes As Boolean = True
Public DatetimePickers As Boolean = True
Public TabControls As Boolean = True
Public RadioButtons As Boolean = True
Public CheckBoxes As Boolean = True
Public TextBoxes As Boolean = False
'''''''''''
Each of this variables enables or disables the sweep for it's control types and all controls that inherits from this type , Thx to kleinma he helped me in the inheritance part.
good luck all and i wish you can use it in your software easily. Please keep me posted if anybody upgrades my code as i may need the modifications to use myself.
Re: Check this Module out, if you understand it then you will use it (-:
Originally Posted by mendhak
That's pretty good, I would have gone with XML files myself.
I'm assuming this is for 1.1? Because VB 2.0 has "My.Settings".
It looks like it is XML, so what are you seeing?
Personally, I would have used binary serialization, since it is a class, and therefore amenable to that. That would create a fast and small file.
I've never had a need to do something like this, but I certainly applaud the approach. Encapsulating functionality into a stand-alone class like this is the very ideal of OO.
Re: Check this Module out, if you understand it then you will use it (-:
What about XML Serialization? That's what I do.
BTW, I haven't had time to look through your Module but I assume you just enumerate through the Controls within the form and save their name and data? If that's the case, wouldn't that not include any private controls (which is default in VB)?
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!
Re: Check this Module out, if you understand it then you will use it (-:
Nice, thanks.
"Imagination is more important than knowledge..."
Albert Einstein
----------------------------------------------- If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway
Re: Check this Module out, if you understand it then you will use it (-:
Originally Posted by maged
i dont understand what u mean, can u explain more
You have Public and Private variables. Public can be seen and accessed by anything but Private can only be accessed within that class it's declared it. Most controls you use are automatically set as Private.
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!
Re: Check this Module out, if you understand it then you will use it (-:
ah i got u now,
the point of this class is to be declared inside the form itself, this way it will automatically has access to all controls - including private controls -
Re: Check this Module out, if you understand it then you will use it (-:
Originally Posted by maged
the point of this class is to be declared inside the form itself, this way it will automatically has access to all controls - including private controls -
right ?
Yup. For some reason I was thinking it would be declared outside the Form.
Nifty
Originally Posted by kleinma
since when are controls in VB declared private by default??? Last time I looked they get declared friend when you add a control to a form.
Oh my bad. I'm used to C#
KrisSiegel.com - My Personal Website with my blog and portfolio Don't Forget to Rate Posts!