VB 怎么保存界面所有控件的信息
因为开发的软件为多文档格式,运行过程中用户可以自行在软件界面上绘制控件(动态创建控件),用户操作完成后可以对当前工程进行保存,以便下次重新导入.
现在的问题是如何把当前窗体上所有控件属性及数据信息进行保存,我的思路是在窗体Unload时把控件信息写入外部INI中,Load时再从INI中读入,但是在保存为INI时不好操作,例如运行过程中要在窗体上动态分层放置很多PictureBox控件,再在其中创建其他控件,在Unload时,控件的left,top,width,height容易保存,但是读入时怎么知道其具体位置呢(属于哪一个容器),再者由于控件的属性各异,保存时如何分类?
目前还未想出妥善的解决办法,请大家帮我提供思路!谢谢.
追问:动态创建时,保存怎么知道控件属于哪个容器?
答案:不知道你看关于文件格式的文档没 如 JPg,TIF如果你看过你会怎么很多关于文件保存的问题
你要开发多文档!麻烦是肯定的!自己建立一个格式
像你这样的
type 容器
Type长度 as integer
容器名称 as string*50
容器Left as long
.....
内部对象Off as long '文件中的指针。。。。
end type
type 内部对象
对象名 as string * n
.....
end type
Private Sub Form_Unload(Cancel As Integer)
Dim ctl As Control
Open app.path & "\controls.ini" For Output As #1
For Each ctl In Me
With ctl
Print #1, "[" & .Name & "]" '这个是name
Print #1, "Size=" & .Width; "," & .Height ‘尺寸
Print #1, "Container=" & .Container.Name '容器
Print #1, "Position=" & .Top & "," & .Left '位置
Print #1, "Type=" & TypeName(ctl) ‘控件类型,创建时VB.xxx这个就可以了
End With
Next
Close #1
end sub
''''''''''''''''''''''''''''''''''''''
创建控件的代码给你参考下
me.Controls.Add "VB.CommandButton", "cmdOk", picture1
With me!cmdOk
.Visible = True
.Width =
.
.
.
End With
VERSION 5.00
Begin VB.Form Form4
Caption = "Form4"
ClientHeight = 6000
ClientLeft = 60
ClientTop = 345
ClientWidth = 9885
LinkTopic = "Form4"
ScaleHeight = 6000
ScaleWidth = 9885
StartUpPosition = 3 '窗口缺省
Begin VB.Label Label1
Caption = $"Form4.frx":0000
BeginProperty Font
Name = "宋体"
Size = 42
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 5775
Left = 0
TabIndex = 0
Top = 0
Width = 9735
End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Label1_Click()
Form2.Show
Unload Me
End Sub
上一个:vb.net中InStr函数怎么用?
下一个:vb中的rnd函数怎么用??