Click here to Skip to main content
12,760,703 members (36,071 online)
Click here to Skip to main content
Add your own
alternative version

Stats

6.5K views
2 bookmarked
Posted 14 Jun 2010

Saving Settings

, 21 Jun 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Saving a form's settings
The aim is to get the properties of the Form and the controls in it and save it to a string called frmstring.
'Global Declaration
Dim frmstring as String
'The code below can be in any subroutine
 Dim frm As Assembly = Assembly.LoadFile(Application.ExecutablePath)
        For Each s As Type In frm.GetTypes
            frmstring = frmstring & frm.GetName.FullName
            For Each m As PropertyInfo In s.GetProperties
                Try
                    frmstring = frmstring & (m.Name & " : " & m.GetValue(Me, Nothing)) & vbCrLf
'm.Name is the property name. m.GetValue gets the value of that property of Me(The form)
                Catch ex As Exception

                End Try

            Next

            frmstring = frmstring & "------------------------" & vbCrLf
        Next

        For Each ctrl As Control In Me.Controls
            frmstring = frmstring & ctrl.Name & vbCrLf
            Dim z = ctrl.GetType()
'This is for enumerating the properties of that control.
            For Each n As PropertyInfo In z.GetProperties
                Try
                    frmstring = frmstring & (n.Name) & " : " & n.GetValue(ctrl, Nothing).ToString & vbCrLf
'n.Name is the property name of the control. n.getvalue returns the value of that property of ctrl(the current control in the form's control list)
                Catch ex As Exception

                End Try

            Next

        Next

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Anshul R
Student
India India
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
GeneralMy reason for a vote of 2 1. You trap for errors and do no... Pin
Simon_Whale14-Jul-10 2:08
memberSimon_Whale14-Jul-10 2:08 
GeneralReason for my vote of 2 you saved the FullName of the type a... Pin
William Winner21-Jun-10 12:05
memberWilliam Winner21-Jun-10 12:05 
GeneralRestoring is simple. Scan the string line by line. Check i... Pin
pranav9515-Jun-10 18:25
memberpranav9515-Jun-10 18:25 
GeneralReason for my vote of 2 1) Global vars = bad! 2) What are y... Pin
Johnny J.14-Jun-10 21:22
memberJohnny J.14-Jun-10 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 21 Jun 2010
Article Copyright 2010 by Anshul R
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid