如何在程序运行时动态创建控件数组?
就是运行的时候创建控件数组,而且数组的惟数是可变的

解决方案 »

  1.   

    把下面内容写在记事本中,保存为  .frm  文件就可以了。VERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3090
       ClientLeft      =   60
       ClientTop       =   450
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3090
       ScaleWidth      =   4680
       StartUpPosition =   3  '窗口缺省
       Begin VB.OptionButton OptButton 
          Caption         =   "Option2"
          Height          =   495
          Index           =   1
          Left            =   2760
          TabIndex        =   6
          Top             =   360
          Width           =   1215
       End
       Begin VB.OptionButton OptButton 
          Caption         =   "Option1"
          Height          =   495
          Index           =   0
          Left            =   2760
          TabIndex        =   5
          Top             =   0
          Width           =   1215
       End
       Begin VB.PictureBox PicDisplay 
          Height          =   615
          Left            =   2520
          ScaleHeight     =   555
          ScaleWidth      =   1635
          TabIndex        =   3
          Top             =   2280
          Width           =   1695
       End
       Begin VB.CommandButton CmdClose 
          Caption         =   "关闭"
          Height          =   495
          Left            =   480
          TabIndex        =   2
          Top             =   2160
          Width           =   1215
       End
       Begin VB.CommandButton CmdDelete 
          Caption         =   "删除"
          Height          =   495
          Left            =   480
          TabIndex        =   1
          Top             =   1560
          Width           =   1215
       End
       Begin VB.CommandButton CmdAdd 
          Caption         =   "增加"
          Height          =   495
          Left            =   480
          TabIndex        =   0
          Top             =   960
          Width           =   1215
       End
       Begin VB.Label Label1 
          AutoSize        =   -1  'True
          Caption         =   "选择一个选项按钮"
          Height          =   180
          Left            =   240
          TabIndex        =   4
          Top             =   120
          Width           =   1440
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Dim MaxId As IntegerPrivate Sub CmdAdd_Click()
    If MaxId = 0 Then MaxId = 1
    If MaxId > 8 Then Exit Sub
    MaxId = MaxId + 1
    Load OptButton(MaxId)
    OptButton(0).SetFocus
    OptButton(MaxId).Top = OptButton(MaxId - 1).Top + 400
    OptButton(MaxId).Visible = True
    OptButton(MaxId).Caption = "Option" & MaxId + 1End SubPrivate Sub CmdClose_Click()
    Unload Me
    End SubPrivate Sub CmdDelete_Click()
    If MaxId <= 1 Then Exit Sub
    Unload OptButton(MaxId)
    MaxId = MaxId - 1
    OptButton(0).SetFocus
    End SubPrivate Sub OptButton_Click(index As Integer)
    PicDisplay.BackColor = QBColor(index + 1)
    End Sub