回 帖 发 新 帖 刷新版面

主题:请教读写问题

在ini文件的保存中如何保存checkbox和combobox两个选择控件,并在读取时如何显示。谢谢!!!并且如何判断第一次点击checkbox被选择,第二次点击选择被取消呢?

回复列表 (共5个回复)

沙发

表达不清楚.保存其VALUE值不就行了?

板凳

如果保存value也要判断是不是被选择了啊!并且读取的时候如果显示你已经的选择。

3 楼

你就把ini文件当作txt文件读写不就行了?

4 楼

[quote]并且如何判断第一次点击checkbox被选择,第二次点击选择被取消呢?[/quote]控件自身有这个功能,无须编写代码。

5 楼

给你一个示例代码
Private Declare Function GetPrivateProfileInt Lib "Kernel32" _
                Alias "GetPrivateProfileIntA" _
                (ByVal lpApplicationName As String, _
                ByVal lpKeyName As String, _
                ByVal nDefault As Long, _
                ByVal lpFileName As String) _
                As Long
Private Declare Function GetPrivateProfileString Lib "Kernel32" _
                Alias "GetPrivateProfileStringA" _
                (ByVal lpApplicationName As String, _
                ByVal lpKeyName As Any, _
                ByVal lpDefault As String, _
                ByVal lpReturnedString As String, _
                ByVal nSize As Integer, _
                ByVal lpFileName As String) _
                As Integer

Private Declare Function WritePrivateProfileString Lib "Kernel32" _
                Alias "WritePrivateProfileStringA" _
                (ByVal lpApplicationName As String, _
                ByVal lpKeyName As String, _
                ByVal lpString As String, _
                ByVal lpFileName As String) _
                As Long
Private Declare Function GetPrivateProfileSection Lib "Kernel32" _
                Alias "GetPrivateProfileSectionA" _
                (ByVal lpAppName As String, _
                ByVal lpReturnedString As String, _
                ByVal nSize As Long, _
                ByVal lpFileName As String) _
                As Long
Private Declare Function WritePrivateProfileSection Lib "Kernel32" _
                Alias "WritePrivateProfileSectionA" _
                (ByVal lpAppName As String, _
                ByVal lpString As String, _
                ByVal lpFileName As String) _
                As Long

Dim FILE_NAME As String
Private Sub Form_Load()
    FILE_NAME = App.Path + "\test.ini"
    Dim strCaption As String * 256
    Call GetPrivateProfileString("Form", "Caption", "Default Caption", _
                        strCaption, 256, FILE_NAME)
    Me.Caption = Trim(strCaption)
    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)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim strCaption As String
    strCaption = Me.Caption
    Call WritePrivateProfileString("Form", "Caption", strCaption, FILE_NAME)
    Call WritePrivateProfileString("Form", "Width", Str(Me.Width), FILE_NAME)
    Call WritePrivateProfileString("Form", "Height", Str(Me.Height), FILE_NAME)
    Call WritePrivateProfileString("Form", "Left", Str(Me.Left), FILE_NAME)
    Call WritePrivateProfileString("Form", "Top", Str(Me.Top), FILE_NAME)
End Sub

我来回复

您尚未登录,请登录后再回复。点此登录或注册