将fm20.dll已经应用到项目中,但是开发状态下没有在form中应用,想在运行时动态添加其中的commandbutton按钮。
如果form中已有一个这样的按钮可以,空的就不行,可能需要引用一下,如何做,望高手指教!

解决方案 »

  1.   

    Private Sub CommandButton1_Click()
        Dim AddCom As Control
        
        If AddCom Is Nothing Then
           Set AddCom = Me.Controls.Add("Forms.CommandButton.1", "CommandButtonA", Me)
           AddCom.Caption = "ASDADF"
           AddCom.Move 100, 100, 300, 300
           AddCom.Visible = True
        End If
    End Sub
      

  2.   

    代码:
    Private Sub Form_Load()
     Dim cmb As MSForms.CommandButton
     Set cmb = Controls.Add("Forms.CommandButton.1", "cmb") '动态添加
     cmb.Left = 10
     cmb.Top = 10
     cmb.Visible = True
    End Sub然后在菜单project ->Project Properties -->Make -->去掉选项Remove information about unused Active controls就可以了,但这样虽然代码可以运行了,但这样会使你编译的exe文件得比较大,不推荐使用!
      

  3.   

    打包时将1999-04-13  10:27              805,180 FM20.AW
    1999-02-09  08:50              370,547 FM20.CHM
    1997-04-01  00:00               18,177 FM20.CNT
    2000-09-20  23:03            1,109,264 FM20.DLL
    2001-06-13  14:16              347,136 FM20.oca
    1999-04-26  20:33               26,384 FM20CHS.DLL
    1999-07-29  11:11               36,864 FM20ENU.DLL这7个文件添加到文件包中。
    (注:将删除未使用的控件信息 取消也没用,在目标机上一样会报错,因为VB在打包FORM2.0时将漏掉两三个DLL文件)