如何用函数动态生成新的控件(picturebox),并将新生成的控件包含在父控件中,而不是窗体中

解决方案 »

  1.   

    set oPic=me.controls.add("VB.PictureBox","pic")
      

  2.   

    '在窗体上加一个CommandButton和一个Frame
    Private Sub Command1_Click()
    Dim l As VB.Label
    Set l = Controls.Add("VB.Label", "Label1", Frame1)
    With l
        .Left = 100
        .Top = 200
        .Height = 300
        .Width = 1000
        .Caption = "ss"
        .Visible = True
    End With
    End Sub
      

  3.   

    提示控件数组元素1不存在(因为为最开始时,有一个PIC(0)的控件,所以在外层加循环,还是只能新建一个控件后就出错了)
      

  4.   


    Private Sub Command1_Click()
    Dim l As VB.Label, i As Long
    For i = 1 To 3
        Set l = Controls.Add("VB.Label", "Label" & CStr(i), Frame1)
        With l
            .Left = 100
            .Top = 300 * i
            .Height = 300
            .Width = 1000
            .Caption = "ss"
            .Visible = True
        End With
    Next i
    End Sub
      

  5.   

    窗体设计时在父控件中建一个picturebox(0),控件数组
    程序中
    for i=0 to numb
    load picturebox(i)
    next i
    然后将添加的控件移到正确的位置