-
1 Attachment(s)
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.
please post me your opinions
rgds
PS: the class file is attached with the thread
-
Re: Check this Module out, if you understand it then you will use it (-:
It's really good, and great
Thanks
-
Re: Check this Module out, if you understand it then you will use it (-:
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".
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
Originally Posted by mendhak
I'm assuming this is for 1.1? Because VB 2.0 has "My.Settings".
It's ready code, I'll use it for both. it really is great
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
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 (-:
thank you all for your replies, i know it can be little modified for more performance. and that i will do when i have some spare time.
also regarding the serialization process, i agree serialization is fast and lighter but xml files can be even modified throught text editor.
so this setting file can be edited with custom settings from outside the software.
anyway i am glad you agree on my work
rgds
-
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)?
-
Re: Check this Module out, if you understand it then you will use it (-:
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
If that's the case, wouldn't that not include any private controls (which is default in VB)?
i dont understand what u mean, can u explain more :confused:
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
Originally Posted by maged
i dont understand what u mean, can u explain more :confused:
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.
-
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 ;) -
right ?
-
Re: Check this Module out, if you understand it then you will use it (-:
if you are using a base form inside your project and inherits from it to all other your application form, then it wont be a problem.
just declare the class inside the base form and it will work along all inherited forms
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
Originally Posted by kasracer
If that's the case, wouldn't that not include any private controls (which is default in VB)?
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.
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
Originally Posted by Shaggy Hiker
It looks like it is XML, so what are you seeing?
Intonation, my dear hiker, intonation.
-
Re: Check this Module out, if you understand it then you will use it (-:
Quote:
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
Quote:
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# :p
-
Re: Check this Module out, if you understand it then you will use it (-:
what do u mean by this mendhak, sorry but my mother tongue is not english :)