Simple XML Serialized Settings
6
I use something similar to this in an application named Shock 3. It provides you with your own Custom settings that can handle your own Custom types as well.
Imports System.XML.Serialization
Public Class SettingsObject
Public MainLocation As Location
Public MainSize As Size
Public LastUsed As DateTime
End Class
Dim MySettings As SettingsObject
Public Shared Function ReadSettings(ByVal fileName As String) As Boolean
Dim serializer As New XmlSerializer(GetType(SettingsObject))
Dim reader As New FileStream(fileName, FileMode.Open)
Try
MySettings = CType(serializer.Deserialize(reader), SettingsObject)
Call reader.Close()
Return True
Catch ex As Exception
Call reader.Close()
Debug.WriteLine(ex.ToString)
Return False
End Try
End Function
Public Shared Function SaveSettings(ByVal fileName As String) As Boolean
Try
Dim serializer As New XmlSerializer(GetType(SettingsObject))
Dim writer As New StreamWriter(fileName, False)
Call serializer.Serialize(writer, SettingsInstance)
Call writer.Close()
Return True
Catch ex As Exception
Debug.WriteLine(ex.ToString)
Return False
End Try
End Function
MySettings.MainLocation = frmMain.Location
MySettings.MainSize = frmMain.Size
MySettings.LastUsed = DateTime.Now
'These settings can be changed at any time. It doesn't have to be before the actual saving.
SaveSettings("C:\testing.xml") 'Save our Settings
Good luck,
-Allen






There are currently no comments for this snippet.