English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

不知visaul basic 6.0 可不可以動態產生物件
就是依照我一開始給的參數而動態產生如button lable ……等物件~
沒用到的就不產生~不是隱藏哦~~

2006-05-02 07:00:54 · 2 個解答 · 發問者 小男 2 in 電腦與網際網路 程式設計

2 個解答

'請設置1個TextBox,Name=Text1,Index=0Dim Label1 As Label '無事件程序的LabelDim WithEvents Command1 As CommandButton '有事件程序的CommandButtonPrivate Sub Form_Load()'設定Text1(0)的屬性Text1(0).Top = 0: Text1(0).Left = 0: Text1(0).Height = 300: Text1(0).Width = 1500: Text1(0) = "原本的TextBox"'利用Load的方式載入Text1(1)Load Text1(1)'設定Text1(1)的屬性Text1(1).Top = 400: Text1(1).Left = 0: Text1(1) = "動態新增的TextBox"Text1(1).Width = 1800: Text1(1).Visible = True'利用Add的方式載入Label1Set Label1 = Controls.Add("VB.Label", "Label1")'設定Label1的屬性Label1.Width = 1500: Label1.Height = 300: Label1.Caption = "動態新增的Label"Label1.Top = 800: Label1.BorderStyle = 1: Label1.Visible = True'利用Add的方式載入Command1Set Command1 = Controls.Add("VB.CommandButton", "Command1")'設定Command1的屬性Command1.Top = 1500: Command1.Caption = "移除物件": Command1.Visible = TrueEnd Sub'因為以WithEvents宣告所以Command1有事件程序可用Private Sub Command1_Click()'用Load的方式載入須用Unload的方式移除Unload Text1(1)'用Add的方式載入須用Remove的方式移除Controls.Remove Label1Controls.Remove Command1End Sub

2006-05-02 08:12:45 · answer #1 · answered by W.J.S. 7 · 0 0

先放一個Button在表單上面。
將"索引值"填上"0",這樣就建立了Button的物件陣列。
以後要增加的時候,加入下面的程式碼:

Load Command1(1)
Command1(1).Move 0, 0
Command1(1).Visible = True

這樣就多增加一個了~

2006-05-02 07:45:47 · answer #2 · answered by 阿宏 2 · 0 0

fedest.com, questions and answers