Click here to Skip to main content
Click here to Skip to main content

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

Comments and Discussions

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

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

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

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