如何通过代码进行添加控件?

解决方案 »

  1.   

    Dim WithEvents ctlCommand As VB.CommandButtonPrivate Sub ctlCommand_Click()
        MsgBox "click"
    End SubPrivate Sub Form_Load()
    Set ctlCommand = Controls.Add("VB.CommandButton", "ctlCommand1", Me)
    '设置CommandButton的位置和尺寸ctlCommand.Top = 400 + 200
    ctlCommand.Left = 20'设置CommandButton的标题
    ctlCommand.Caption = "点击"
    '使CommandButton可见
    ctlCommand.Visible = TrueEnd Sub
      

  2.   

    '先有form1上加一个text1 (0)Private Sub Form_Load()
        For i = 1 To 10
            Load Text1(i)
            Text1(i).Top = 400 * i + 200
            Text1(i).Left = 20
            Text1(i).Visible = True
        Next
    End Sub
      

  3.   

    同意上面的做法,建议你看看VB的帮助,关于ActiveX.exe ,ActiveX.dll部分