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.