各位大人。小弟请教一个问题。
一个窗口上有一个picbox控件,小弟还作了一个可视的用户控件。问题,小弟想动态生成该用户控件,并让该控件在picbox这个容器中显示。请问代码怎么写?
小弟跪谢/

解决方案 »

  1.   

    LoadDynamicControl ("应用名.用户控件")
    具体显示你试试吧
      

  2.   

    Dim x As PictureBoxPrivate Sub Command3_Click()
        Set x = Controls.Add("VB.PictureBox", "pic1", Picture1)
        x.Visible = True
    End Sub
      

  3.   

    用控件数组
    再用load()动态载如
      

  4.   

    给你两种方法参考:
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate WithEvents NewButton As CommandButton
    Private WithEvents NewPic As PictureBox
    Private WithEvents NewText As TextBoxPrivate Sub Form_Load()
        Set NewPic = Controls.Add("VB.PictureBox", "PicNew", Me)
        NewPic.Move 0, 0, Me.Width / 2, Me.Height / 2
        NewPic.Visible = True
    End SubPrivate Sub NewPic_Click()
        Set NewButton = Controls.Add("VB.CommandButton", "cmdNew", Me)
        NewButton.Visible = True
        Set NewButton.Container = NewPic
        NewButton.Move 0, 0, 1000, 1000
    End SubPrivate Sub NewButton_Click()
        Set NewText = Controls.Add("VB.TextBox", "txtNew", Me)
        NewText.Visible = True
        SetParent NewText.hWnd, NewPic.hWnd
        NewText.Move NewButton.Width + 1, NewButton.Top, 1000, 1000
    End Sub