65.9K
CodeProject is changing. Read more.
Home

Saving Settings

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.60/5 (4 votes)

Jun 15, 2010

CPOL
viewsIcon

12966

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