不在窗体上直接画cmd控件,而用声明控件对象(dim cmd as commandbutton)的
方法使控件出现在窗体上??

解决方案 »

  1.   


    Dim WithEvents oControl As CommandButton
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate Sub btn1_Click()   '                        vb-你控件的工程名    TextBox-你控件的类名     newText-生成后的控件名称
       Set oControl = Controls.Add("VB.CommandButton", "newcmd", Me)    With oControl
             
            .Visible = True                     '显示
            .Left = 100
            .Top = 100
            .Width = 1800
            .Caption = "这是你要的控件"
         
        End With
      
    End Sub
    Private Sub oControl_click()
      MsgBox "adf"
    End Sub
      

  2.   

    可以,那个API没用,你可以去掉。