Private Sub Command2_Click()
Set oControl = Controls.Add("IssueMachine.DeviceRun_2", "MapView")
oControl.Visible = True '可以看到了
End SubPrivate Sub Command3_Click()
Dim aa As IssueMachine.DeviceRun_2
Set aa = New DeviceRun_2
aa.SetConfig '这里可以执行了
End Sub这是动态加载控件的代码,但是有个问题搞不懂,Command2_Click里可以显示出控件,但是没法帮定方法
Command3_Click()里可以帮定方法却又不能显示
请教我一个两全其美的办法吧

解决方案 »

  1.   

    自己参考吧Dim   WithEvents   cmdMyCommand   As   VB.CommandButton   
              Option   Explicit   
        
              Dim   WithEvents   ctlDynamic   As   VBControlExtender   
              Dim   WithEvents   ctlText   As   VB.TextBox   
              Dim   WithEvents   ctlCommand   As   VB.CommandButton   
              Dim   WithEvents   ctlCommandDel   As   VB.CommandButton   
              Private   Sub   ctlCommandDel_Click()   
                      Dim   i   As   Integer   
                        
                      Licenses.Remove   "MSComctlLib.TreeCtrl"   
                      If   MsgBox("是否删除所有控件",   vbYesNo)   =   vbYes   Then   
                      For   i   =   1   To   Form1.Controls.Count   
                              Controls.Remove   0   
                      Next   i   
                      End   If   
              End   Sub   
              Private   Sub   ctlCommand_Click()   
                      ctlText.Text   =   "你点击的是控制按钮"   
              End   Sub   
        
              Private   Sub   ctlDynamic_ObjectEvent(Info   As   EventInfo)   
                      If   Info.Name   =   "Click"   Then   
                              ctlText.Text   =   "你点击的条目是   "   &   _   
                                              ctlDynamic.object.selecteditem.Text   
                      End   If   
              End   Sub   
        
              Private   Sub   Form_Load()   
                      Dim   i   As   Integer   
                      Licenses.Add   "MSComctlLib.TreeCtrl"   
        
                      Set   ctlDynamic   =   Controls.Add("MSComctlLib.TreeCtrl",   _   
                                                      "myctl",   Form1)   
                      ctlDynamic.Move   1,   1,   2500,   3500   
                      For   i   =   1   To   10   
                              ctlDynamic.object.nodes.Add   Key:="Test"   &   Str(i),   _   
                                              Text:="Test"   &   Str(i)   
                              ctlDynamic.object.nodes.Add   Relative:="Test"   &   Str(i),   _   
                                              Relationship:=4,   Text:="TestChild"   &   Str(i)   
                      Next   i   
                      ctlDynamic.Visible   =   True   
        
                      Set   ctlText   =   Controls.Add("VB.TextBox",   "ctlText1",   Form1)   
                      ctlText.Move   (ctlDynamic.Left   +   ctlDynamic.Width   +   50),   _   
                                                      1,   2500,   100   
                      ctlText.BackColor   =   vbBlue   
                      ctlText.ForeColor   =   vbWhite   
                      ctlText.Visible   =   True   
        
                      Set   ctlCommand   =   Controls.Add("VB.CommandButton",   _   
                                                      "ctlCommand1",   Form1)   
                      ctlCommand.Move   (ctlDynamic.Left   +   ctlDynamic.Width   +   50),   _   
                                                      ctlText.Height   +   50,   1500,   500   
                      ctlCommand.Caption   =   "点击"   
                      ctlCommand.Visible   =   True   
                        
                      Set   ctlCommandDel   =   Controls.Add("VB.CommandButton",   _   
                                                      "ctlCommand2",   Form1)   
                      ctlCommandDel.Move   (ctlDynamic.Left   +   ctlDynamic.Width   +   50),   _   
                                                      ctlText.Height   +   650,   1500,   500   
                      ctlCommandDel.Caption   =   "删除所有控件"   
                      ctlCommandDel.Visible   =   True   
              End   Sub   
      

  2.   

    这里的函数都是object的,如果是自定义的方法就出错了
      

  3.   

    Private WithEvents oControl As VBControlExtender
    Private Sub Command2_Click()
    Set oControl = Controls.Add("IssueMachine.DeviceRun_2", "MapView")
    With oControl
        .Visible = True '可以看到了
    End With
    End SubPrivate Sub Command3_Click()
    With oControl÷
        '刚才写成这样了
         '.object. SetConfig
        .object.SetConfig
    End With
    End Sub
    不过新问题出来了,setconfig要触发自定义事件怎么触发呢
      

  4.   

    问下super_xxx  您的COMMAND3里 是绑定 对象与控件的数据么?
      

  5.   

    Private Sub Command2_Click() 
    Set oControl = Controls.Add("IssueMachine.DeviceRun_2", "MapView") 
    oControl.Visible = True '可以看到了 
    oControl.Object.SetConfig
    End Sub 
      

  6.   

    Private Sub Command2_Click()
    Set oControl = Controls.Add("IssueMachine.DeviceRun_2", "MapView")
    With oControl
        .Visible = True '可以看到了
    End With
    End Sub    Private Sub Command3_Click()
        
    '    On Error GoTo errHandle
        With oControl
            .object.btSwitch.Enabled = True
            .object.btOK.Enabled = True
            .SetConfig '这里可以执行了
            .object.add_DevComUsed = 1000 ' EnumWindows(AddressOf MyWindowsListProc) '这里还不对,本意是要加个事件在控件里调用这个事件
        End With
    '    Exit Sub
    'errHandle:
    '    RaiseEvent error
        End Sub
    '这是事件处理函数
    Function MyWindowsListProc(ee As String)
    MsgBox ("aaa")
    End Function
      

  7.   

    那个事件是你对象本来就有的么,还是需要回调的         
     Private   Sub   oControl_ObjectEvent(Info   As   EventInfo)   
          If   Info.Name   =   "你的事件名"   Then   
              处理事件
          End   If   
     End   Sub   
      

  8.   

     oControl.object.add 方法的原型你这个Add方法是需要传入一个函数的地址?
      

  9.   

    Sub add_DevComUsed(value As DeviceError)
    原型
    我是要加个函数地址,让com调用
      

  10.   

    public delegate void DeviceError(string aaa) c#里定义得接口类型
    msn:[email protected]