如何利用数组增加控件,例如增加text,label之类的

解决方案 »

  1.   

    先在设计环境下,给该控件的index属性赋值,比如0
    代码:
    load text1(1)
    with text1(1)
        .move 1000,1000,300,1000
        .visible=true
    end with
      

  2.   

    以前的贴子,再贴一次:通过Add方法实现
    Add方法在Controls集合中添加一个控件并返回一个对控件的引用。Add方法的语法为:Object.Add(ProgID,Name,Container)其中Object为要添加元素的集合,ProgID为标示的字符串.可通过对象浏览器来确定,例如,CommandButton控件的ProgID是VB.CommandButton. Name是控件的名称. Container是包含添加控件的容器,可以为form或Frame控件等等。        Option Explicit    '通过使用WithEvents关键字声明一个对象变量为新的命令按钮        Private WithEvents NewButton As CommandButton        '增加控件        Private Sub Command1_Click()        If NewButton Is Nothing Then        '增加新的按钮cmdNew        Set NewButton = Controls.Add("VB.CommandButton", "cmdNew", Me)        '确定新增按钮cmdNew的位置        NewButton.Move Command1.Left + Command1.Width + 240, Command1.Top        NewButton.Caption = "新增的按钮"        NewButton.Visible = True        End If        End Sub        '新增控件的单击事件Private Sub NewButton_Click()        MsgBox "您选中的是动态增加的按钮!"End Sub
      

  3.   

    http://www.china-askpro.com/msg1/qa98.shtml
      

  4.   

    Private Sub Command1_Click()
        Call CreateControls(Form1, "VB.PictureBox", "VB.TextBox", 20)
    End SubSub CreateControls(oContainer As Object, ByVal sParentCtrlName As String, ByVal sChildCtrlName As String, ByVal lCtrlCount As Long)
        On Error Resume Next
        Dim i As Long
        Dim oParentCtrl As Object, oChildCtrl As Object
        For i = 1 To lCtrlCount
            Set oParentCtrl = Controls.Add(sParentCtrlName, "pctrl" & CStr(i), oContainer)
    With oParentCtrl
                .Visible = True
                .Move i * 250, i * 250
            End With
            
            Set oChildCtrl = Controls.Add(sChildCtrlName, "cctrl" & CStr(i), oParentCtrl)
            With oChildCtrl
                .Visible = True
                .Move 0, 0
            End With
        Next
    End Sub
      

  5.   

    Option Explicit
    Private WithEvents btnObj As CommandButtonPrivate Sub btnObj_Click()
       MsgBox "This is a dynamically added button."
    End SubPrivate Sub Form_Load()
       Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
       With btnObj
          .Visible = True
          .Width = 2000
          .Caption = "Hello"
          .Top = 1000
          .Left = 1000
       End With
    End Sub
      

  6.   

    麻烦发一下自动用数组增加text的命令出来
      

  7.   

    关注: 如果是要创建一个控件数组,但在设计阶段又不能有这个控件数组中的一个元素,以便以后好用UNLOAD删除这个控件数组的全部控件,请问怎么弄,另请教WEBBROWSER的PROGID是什么
      

  8.   

    有谁可以发一下,利用数组增加lablel控件的???