![]() |
#2
bczgvip2013-01-22 12:55
![]() Option Explicit 可以自己用了。。。话说,咱一般都是用INI的呐,这个也不错。Private Sub Command1_Click() SaveSettingEx Text1, Text2, Text3, Text4, Text5, Text6 End Sub Private Sub Command2_Click() DeleteSettingEx Text1, Text2, Text3, Text4, Text5, Text6 End Sub Private Sub Form_Load() Me.Width = GetSetting(App.Title, Me.Name, "Width", 7200) Me.Height = GetSetting(App.Title, Me.Name, "Height", 6300) Me.Top = GetSetting(App.Title, Me.Name, "Top", 100) Me.Left = GetSetting(App.Title, Me.Name, "Left", 100) GetSettingEx Text1, Text2, Text3, Text4, Text5, Text6 End Sub Private Sub Form_Unload(Cancel As Integer) If Me.WindowState <> vbMinimized Then '最小化退出有点问题。负值 Call SaveSetting(App.Title, Me.Name, "Width", Me.Width) Call SaveSetting(App.Title, Me.Name, "Height", Me.Height) Call SaveSetting(App.Title, Me.Name, "Top", Me.Top) Call SaveSetting(App.Title, Me.Name, "Left", Me.Left) End If End Sub Public Sub DeleteSettingEx(ParamArray vControls() As Variant) Dim v As Variant For Each v In vControls If TypeOf v Is TextBox Then ' 可以自行添加别的控件设置 CommandButton TextBox 等 Call DeleteSetting(App.Title, Me.Name, v.Name) End If Next End Sub Public Sub GetSettingEx(ParamArray vControls() As Variant) Dim v As Variant For Each v In vControls If TypeOf v Is TextBox Then ' 可以自行添加别的控件设置 CommandButton TextBox 等 v.Text = GetSetting(App.Title, Me.Name, v.Name, "默认值") '默认值自己设置 End If Next End Sub Public Sub SaveSettingEx(ParamArray vControls() As Variant) Dim v As Variant For Each v In vControls If TypeOf v Is TextBox Then Debug.Print Me.Name, v.Name, v.Text Call SaveSetting(App.Title, Me.Name, v.Name, v.Text) End If Next End Sub |
只有本站会员才能查看附件,请 登录
这个代码是我搜来的!

Private Sub Form_Load()
Me.Width = GetSetting(App.Title, Me.Name, "Width", 7200)
Me.Height = GetSetting(App.Title, Me.Name, "Height", 6300)
Me.Top = GetSetting(App.Title, Me.Name, "Top", 100)
Me.Left = GetSetting(App.Title, Me.Name, "Left", 100)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SaveSetting(App.Title, Me.Name, "Width", Me.Width)
Call SaveSetting(App.Title, Me.Name, "Height", Me.Height)
Call SaveSetting(App.Title, Me.Name, "Top", Me.Top)
Call SaveSetting(App.Title, Me.Name, "Left", Me.Left)
End Sub
我需要自动保存一些设置好的信息该怎么写呢!列入我填写好一些控件里的信息!可以点击Me.Width = GetSetting(App.Title, Me.Name, "Width", 7200)
Me.Height = GetSetting(App.Title, Me.Name, "Height", 6300)
Me.Top = GetSetting(App.Title, Me.Name, "Top", 100)
Me.Left = GetSetting(App.Title, Me.Name, "Left", 100)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SaveSetting(App.Title, Me.Name, "Width", Me.Width)
Call SaveSetting(App.Title, Me.Name, "Height", Me.Height)
Call SaveSetting(App.Title, Me.Name, "Top", Me.Top)
Call SaveSetting(App.Title, Me.Name, "Left", Me.Left)
End Sub
保存键或者不点击在我关闭工具的时候可以自动保存,打开后自动读取!只用保存一次设置的信息就可以!如果有新信息要输入!我可以点击清除从新设置!
我搜了一下相关资料,像我这样只保存这么一点信息的花可以不用生成TXT或者INI或者数据库!,实现这样的功能我应该怎么写代码呢!!各位师傅帮帮忙了!!谢谢了!!
一下是建立好的工程!方便帮助我的师傅们就不用创建界面了!!
只有本站会员才能查看附件,请 登录