> You could look into Serialization.
That's exactly what I needed! I just didn't know what it was called :'-(
Thanks for pointing me in the right direction.
i.e build a class that stores your variables. Create an instance at
program startup, persist it through a module, and when your program starts
up, add a handler to the applicaiton's exit event, and when it exists, use
a binary formatter to save the class to disk.. on startup again,
deserialize that file, variables ready to go..
When I deserialize my file, do I have to go through and set each one
individually like so:
Label1.ForeColo r = System.Drawing. ColorTranslator .FromOle(mySett ings.color)
Label1.Font.Nam e = mySettings.this font.name
Label1.Font.Siz e = mySettings.this font.size
Or can the class elements be associated with stuff in my form somehow?
Matthew
P.S. My current code looks like this:
'form1.vb contains:
Dim mySettings As Settings = New Settings
mySettings.colo r = System.Drawing. ColorTranslator .ToOle(Label1.F oreColor)
mySettings.this font.name = Label1.Font.Nam e
mySettings.this font.size = Label1.Font.Siz e
mySettings.Save ("settings.xml" , mySettings)
'class1.vb contains:
Imports System.Xml
Imports System.Xml.Sche ma
Imports System.Xml.Seri alization
Imports System.IO
<XmlRoot("confi g")> Public Class Settings
Private _Name As String
Private _Color As String
Private _Font As thisFont = New thisFont
Public Property name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property color() As String
Get
Return _Color
End Get
Set(ByVal Value As String)
_Color = Value
End Set
End Property
<XmlElement("fo nt")> Public Property thisfont() As thisfont
Get
Return _Font
End Get
Set(ByVal Value As thisfont)
_Font = Value
End Set
End Property
Public Shared Sub save(ByVal path As String, ByVal config As Settings)
Dim xs As XmlSerializer = New XmlSerializer(G etType(Settings ))
Dim fs As FileStream = New FileStream(path , FileMode.Create )
xs.Serialize(fs , config)
fs.Close()
End Sub
Public Shared Sub load(ByVal path As String, ByVal config As Settings)
Dim myObject As Settings
Dim xs As XmlSerializer = New XmlSerializer(G etType(Settings ))
Dim fs As FileStream = New FileStream(path , FileMode.Create )
myObject = CType(xs.Deseri alize(fs), Settings)
fs.Close()
End Sub
End Class
<XmlRoot("font" )> Public Class thisFont
Private _name As String
Private _size As String
Private _bold As String
Private _italic As String
Private _strikeout As String
Private _underline As String
<XmlElement("na me")> Public Property name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
<XmlElement("si ze")> Public Property size() As Integer
Get
Return _size
End Get
Set(ByVal Value As Integer)
_size = Value
End Set
End Property
End Class