Dim WithEvents Cmmand1 As CommandButton
Private Sub Cmmand1_Click()
    MsgBox "Hello world!", vbInformation, Me.Caption
End Sub
Set Cmmand1 = Me.Controls.Add("VB.CommandButton", "cmmand1")
   With Form1!Cmmand1
      .Visible = True
      .Top = 1000
      .Width = 2000
      .Caption = "点我!!"
   End With

解决方案 »

  1.   

    错了,是
    Dim WithEvents Cmmand1 As CommandButton
    Private Sub Cmmand1_Click()
        MsgBox "Hello world!", vbInformation, Me.Caption
    End SubPrivate Sub Command1_Click()
    Set Cmmand1 = Me.Controls.Add("VB.CommandButton", "cmmand1")
      With Form1!Cmmand1
          .Visible = True
          .Top = 1000
          .Width = 2000
          .Caption = "点我!!"
      End WithEnd Sub
      

  2.   

    这个我也知道,可是我不能这样声明100个事件吧!像这样……
    Private WithEvents ctlSelf1 As VBControlExtender
    ...
    ...
    ...
    Private WithEvents ctlSelf100 As VBControlExtender
    天哪,救命啊!
    万一我加到了101怎么办?
      

  3.   

    亮MM在这是:
    http://www.csdn.net/Expert/topic/472/472455.shtm
    高手来钓亮MM
      

  4.   

    Private WithEvents ctlSelf() As VBControlExtender
    这样定义吗?
    然后再在下面这样?
    Rim Preserve ctlSelf(100)
    set ctlself(100) = Controls.Add("VB.CommandButton", "cmmand1",form1)然后这个事件这样:
    Private Sub ctlSelf_ObjectEvent(Info As EventInfo,Index as Integer)
        If Info.Name = "GetFocus" Then
            msgbox "It's Error!"
        End If
    End Sub
    可是这样是错的,错的,错的错的
      

  5.   

    你先在窗体上摆一个控件(如TEXTBOX)
    然后COPY它,再粘贴,VB就会提示你是否建立控件数组,
    然后,再把TEXT1(1)删除,只留下TEXT1(0),就好了。
    如果要动态加载一个的话,就如下:
    LOAD TEXT1(I) 'i从1算起!