从您对我的其他答案的评论中推断,我发布了一个关于如何从 INI 文件中读取值的新答案:
Imports System.Text
Imports System.Runtime.InteropServices
Public Class TestForm
'declare the API
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function GetPrivateProfileString(ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
End Function
'Function to retrieve a value from an INI file
Public Function GetINIValue(filename As String, section As String, key As String, Optional defaultValue As String = "") As String
Dim res As Integer
Dim sb As New StringBuilder(500)
res = GetPrivateProfileString(section, key, "", sb, sb.Capacity, filename)
If res = 1 Then Return sb.ToString Else Return defaultValue
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim filename As String = "C:\Scratch\Test.ini"
CheckBox1.Checked = If(GetINIValue(filename, "Display", "bFXAAEnabled") = "1", True, False)
End Sub
End Class