# Re: load,unload

Posted by 东吴电算人 on September 08, 1998 at 17:02:44:

In Reply to: load,unload posted by 询朊 on September 08, 1998 at 16:03:27:

: : 我写一个程式想要动态新增PICTUREBOX或COMMANDBUTTON，CWW指点我用LOAD来新增，可是小弟不才，不知道如何运用，可否详细说明一下（VB线上说明只有说明如何载入FORM的方式，并没有解释如何载入物件的方法）
: : 谢谢！
就是利用物件阵列来作，以下我写的小范例，参考看看..

首先在新开表单上有三个物件, Label1, Command1, Command2
先在 Label1 的 index 属性设为 0 宣告成物件阵列

Dim gintIdx As Integer '宣告物件阵列指标

Private Sub Command1_Click()
'当按下 Command1 时就增加一个 Label 物件

gintIdx = gintIdx + 1
Load Me.Label1(gintIdx) 'Load 进来一个 Label 物件
Me.Label1(gintIdx).Caption = Now() & " Label " & Str(gintIdx)
Me.Label1(gintIdx).Top = Me.Label1(gintIdx - 1).Top + 300
Me.Label1(gintIdx).Left = Me.Label1(gintIdx - 1).Left + 300
Me.Label1(gintIdx).Visible = True '让 Load 进来的物件可以看见
Me.Caption = "Window = " & Str(gintIdx)
End Sub

Private Sub Command2_Click()
'当按下 Command2 时就减少一个 Label 物件

If (gintIdx > 0) Then
Unload Me.Label1(gintIdx) 'UnLoad 掉一个 Label 物件
gintIdx = gintIdx - 1
Me.Caption = "Window = " & Str(gintIdx)
End If
End Sub

Private Sub Form_Load()
gintIdx = 0 '物件阵列指标初始值为 0
End Sub

Follow Ups: