Friday, May 25, 2007

Layout application: Simplify saving and retriving settings

These two function simplify saving and retriving settings for the Layout application.
You will need to add the code for the picture filename.


Private Sub ReadMySettings()

Dim sPathFile As String = Application.StartupPath & "MyData.txt"
Dim aContents

aContents = IO.File.ReadAllText(sPathFile).Split(vbNewLine)

Me.Left = aContents(0)
Me.Top = aContents(1)
Me.Width = aContents(2)
Me.Height = aContents(3)

Me.BackColor = Color.FromArgb(aContents(4), aContents(5), aContents(6), aContents(7))
Me.TransparencyKey = Color.FromArgb(aContents(8), aContents(9), aContents(10), aContents(11))

Label1.BackColor = Color.FromArgb(aContents(12), aContents(13), aContents(14), aContents(15))
Label1.ForeColor = Color.FromArgb(aContents(16), aContents(17), aContents(18), aContents(19))
Label1.Left = aContents(20)
Label1.Top = aContents(21)
Label1.Text = aContents(22)
Label1.Font = New Font(CStr(aContents(23)), CSng(aContents(24)), CLng(aContents(25)), CLng(aContents(26)), CByte(aContents(27)))
Label1.AutoSize = True

MsgBox("Finished", MsgBoxStyle.Information)

End Sub
Private Sub SaveMySettings()

Dim sPathFile As String = Application.StartupPath & "MyData.txt"
Dim sContents As String

sContents = Me.Left & vbNewLine
sContents = sContents & Me.Top & vbNewLine
sContents = sContents & Me.Width & vbNewLine
sContents = sContents & Me.Height & vbNewLine

sContents = sContents & Me.BackColor.A & vbNewLine
sContents = sContents & Me.BackColor.R & vbNewLine
sContents = sContents & Me.BackColor.G & vbNewLine
sContents = sContents & Me.BackColor.B & vbNewLine

sContents = sContents & Me.TransparencyKey.A & vbNewLine
sContents = sContents & Me.TransparencyKey.R & vbNewLine
sContents = sContents & Me.TransparencyKey.G & vbNewLine
sContents = sContents & Me.TransparencyKey.B & vbNewLine

sContents = sContents & Label1.BackColor.A & vbNewLine
sContents = sContents & Label1.BackColor.R & vbNewLine
sContents = sContents & Label1.BackColor.G & vbNewLine
sContents = sContents & Label1.BackColor.B & vbNewLine

sContents = sContents & Label1.ForeColor.A & vbNewLine
sContents = sContents & Label1.ForeColor.R & vbNewLine
sContents = sContents & Label1.ForeColor.G & vbNewLine
sContents = sContents & Label1.ForeColor.B & vbNewLine

sContents = sContents & Label1.Left & vbNewLine
sContents = sContents & Label1.Top & vbNewLine
sContents = sContents & Label1.Text & vbNewLine

sContents = sContents & Label1.Font.Name & vbNewLine
sContents = sContents & Label1.Font.Size & vbNewLine
sContents = sContents & Label1.Font.Style & vbNewLine
sContents = sContents & Label1.Font.Unit & vbNewLine
sContents = sContents & Label1.Font.GdiCharSet & vbNewLine

IO.File.WriteAllText(sPathFile, sContents)

MsgBox("Saved", MsgBoxStyle.Information)
End Sub

No comments: