從您的意見我的其他答案我張貼有關如何從一個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
這不會選項嚴格在編譯! –
已編輯,它現在應該能夠嚴格支持。謝謝。 – surpavan
ToArray選項給出錯誤。有「ToString」可用雖然... –