Public Class Form1
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal nDefault As Integer, _
ByVal lpFileName As String) As Integer
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As System.Text.StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" ( _
ByVal lpAppName As String, _
ByVal lpReturnedString As System.Text.StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" ( _
ByVal lpAppName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Public Const FILE_NAME As String = ".\test.ini"
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If (System.IO.File.Exists(FILE_NAME)) Then
Dim strCaption As New System.Text.StringBuilder(256)
GetPrivateProfileString("Form", "Caption", "Default Caption", _
strCaption, strCaption.Capacity, FILE_NAME)
'Me.Text = strCaption.ToString()
'Me.Width = GetPrivateProfileInt("Form", "Width", Me.Width, FILE_NAME)
'Me.Height = GetPrivateProfileInt("Form", "Height", Me.Height, FILE_NAME)
'Me.Left = GetPrivateProfileInt("Form", "Left", Me.Left, FILE_NAME)
'Me.Top = GetPrivateProfileInt("Form", "Top", Me.Top, FILE_NAME)
Dim T As String = GetPrivateProfileInt("Form", "Width", Me.Width, FILE_NAME) & vbCrLf & _
GetPrivateProfileInt("Form", "Height", Me.Height, FILE_NAME) & vbCrLf & _
GetPrivateProfileInt("Form", "Left", Me.Left, FILE_NAME) & vbCrLf & _
GetPrivateProfileInt("Form", "Top", Me.Top, FILE_NAME)
Me.Label1.Text = T
End If
End Sub
Protected Overrides Sub OnClosing( _
ByVal e As System.ComponentModel.CancelEventArgs)
Dim strCaption As String = Me.Text
WritePrivateProfileString("Form", "Caption", strCaption, FILE_NAME)
WritePrivateProfileString("Form", "Width", Me.Width.ToString(), FILE_NAME)
WritePrivateProfileString("Form", "Height", Me.Height.ToString(), FILE_NAME)
WritePrivateProfileString("Form", "Left", Me.Left.ToString(), FILE_NAME)
WritePrivateProfileString("Form", "Top", Me.Top.ToString(), FILE_NAME)
End Sub
End Class
暂时没有评论