First, heres an ini file class.
Found this online, no credits to me except for some minor edits.
[code=vb]Public Class iniFile
Dim strFilename As String
' Constructor, accepting a filename
Public Sub New(ByVal Filename As String)
strFilename = Filename
End Sub
' Read-only filename property
ReadOnly Property FileName() As String
Get
Return strFilename
End Get
End Property
#Region "Get"
Public Function GetString(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As String) As String
' Returns a string from your INI file
Dim intCharCount As Integer
GetString = [Default]
Dim objResult As New System.Text.StringBuilder(500)
intCharCount = GetPrivateProfileString(Section, Key, _
[Default], objResult, objResult.Capacity, strFilename)
If intCharCount > 0 Then
GetString = Left(objResult.ToString, intCharCount)
End If
End Function
Public Function GetInteger(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As UInt32) As UInt32
' Returns an integer from your INI file
Return GetPrivateProfileInt(Section, Key, _
[Default], strFilename)
End Function
Public Function GetShort(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As UShort) As UShort
' Returns an integer from your INI file
Return GetPrivateProfileInt(Section, Key, _
[Default], strFilename)
End Function
Public Function GetBoolean(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As Boolean) As Boolean
' Returns a boolean from your INI file
Return (GetPrivateProfileInt(Section, Key, _
CInt([Default]), strFilename) = 1)
End Function
#End Region
#Region "Write"
Public Sub WriteString(ByVal Section As String, _
ByVal Key As String, ByVal Value As String)
' Writes a string to your INI file
WritePrivateProfileString(Section, Key, Value, strFilename)
Flush()
End Sub
Public Sub WriteInteger(ByVal Section As String, _
ByVal Key As String, ByVal Value As Integer)
' Writes an integer to your INI file
WriteString(Section, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteInteger(ByVal Section As String, _
ByVal Key As String, ByVal Value As UInt32)
' Writes an integer to your INI file
WriteString(Section, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteShort(ByVal Section As String, _
ByVal Key As String, ByVal Value As Short)
' Writes an integer to your INI file
WriteString(Section, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteBoolean(ByVal Section As String, _
ByVal Key As String, ByVal Value As Boolean)
' Writes a boolean to your INI file
WriteString(Section, Key, CStr(CInt(Value)))
Flush()
End Sub
#End Region
Private Sub Flush()
' Stores all the cached changes to your INI file
FlushPrivateProfileString(0, 0, 0, strFilename)
End Sub
End Class[/code]
Now for my settings code.
First, we have the Setting class
[code=vb] Public Class Setting
Private _Control As Control
Private _Name As String
Public ReadOnly Property Control() As Control
Get
Return _Control
End Get
End Property
Public ReadOnly Property Name() As String
Get
Return _Name
End Get
End Property
Public Property Value() As String
Get
Select Case Control.GetType().Name
Case "ComboBox"
Return CStr(CType(Control, ComboBox).Text)
Case "CheckBox"
Return CStr(CType(Control, CheckBox).Checked)
Case "RaidoButton"
Return CStr(CType(Control, RadioButton).Checked)
Case "TextBox"
Return CStr(CType(Control, TextBox).Text)
Case "NumericUpDown"
Return CStr(CType(Control, NumericUpDown).Value)
Case "TrackBar"
Return CStr(CType(Control, TrackBar).Value)
Case Else
Return ""
End Select
End Get
Set(ByVal value As String)
If value = "" Then Exit Property
Select Case Control.GetType().Name
Case "ComboBox"
CType(Control, ComboBox).Text = CStr(value)
Control.Invalidate()
Case "CheckBox"
CType(Control, CheckBox).Checked = CBool(value)
Case "RaidoButton"
CType(Control, RadioButton).Checked = CBool(value)
Case "TextBox"
CType(Control, TextBox).Text = CStr(value)
Case "NumericUpDown"
CType(Control, NumericUpDown).Value = CStr(value)
Case "TrackBar"
CType(Control, TrackBar).Value = CStr(value)
End Select
End Set
End Property
Public Sub New(ByVal C As Control, ByVal name As String)
_Control = C
_Name = name
End Sub
End Class[/code]
Now, we will declare a list of Settings
[code=vb]Private Settings As New List(Of Setting)[/code]
And we will add settings like so
[code=vb]Settings.Add(New Setting(Form.Control, "SettingNameInTheIniFile"))[/code]
And heres saving and loading
[code=vb]
Public Sub SaveSettings()
If Not IO.File.Exists(Application.StartupPath & "\Config.ini") Then MsgBox("Cannot find Config.ini!", MsgBoxStyle.Critical, "Error!") : Exit Sub
Dim Ini As New iniFile(Application.StartupPath & "\Config.ini")
For Each [Set] As Setting In Settings
Ini.WriteString("Settings", [Set].Name, [Set].Value)
Next
End Sub
Public Sub ClearSettings()
If Not IO.File.Exists(Application.StartupPath & "\Config.ini") Then MsgBox("Cannot find Config.ini!", MsgBoxStyle.Critical, "Error!") : Exit Sub
Dim Ini As New iniFile(Application.StartupPath & "\Config.ini")
For Each [Set] As Setting In Settings
Ini.WriteString("Settings", [Set].Name, "")
Next
End Sub
Public Sub LoadSettings)
If Not IO.File.Exists(Application.StartupPath & "\Config.ini") Then MsgBox("Cannot find Config.ini!", MsgBoxStyle.Critical, "Error!") : Exit Sub
Dim Ini As New iniFile(Application.StartupPath & "\Config.ini")
For Each [Set] As Setting In Settings
[Set].Value = Ini.GetString("Settings", [Set].Name, "")
Next
End Sub
[/code]
Its as simple as that! as you can see, the only controls you can use as of now are:
-ComboBox
-CheckBox
-RaidoButton
-TextBox
-NumericUpDown
-TrackBar
But its not hard to edit the code to do more.
Goodluck!