我要实现textbox和checkbox的自动生成。也就是当在textbox中添加内容
完毕后,回车就能再生成一个textbox。

解决方案 »

  1.   

    在TextBox得Keypresss事件种加入Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then NewTextBox CtrlName
    End SubPublic Sub NewTextBox(ByVal CtrlName As String)
        Dim btnObj As Control
        Set btnObj = Me.Controls.Add("VB.TextBox", "TextBoxName")
        With btnObj
           .Text = Text1.Text
           .Top = 100
           .Left = 100
           .Visible = False
        End With
    End Sub
      

  2.   

    Public Sub NewTextBox(ByVal CtrlName As String)
        Dim btnObj As Control
        Set btnObj = Me.Controls.Add("VB.TextBox", "TextBoxName")
        With btnObj
           .Text = Text1.Text
           .Top = Text1.Top + 200
           .Left = Text1.Left
           .Visible = True             ‘改成TRUE
        End With
    End Sub
      

  3.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then NewTextBox "text1234"
    End SubPublic Sub NewTextBox(ByVal CtrlName As String)
        Dim btnObj As Control
        Set btnObj = Me.Controls.Add("VB.TextBox", CtrlName)
        With btnObj
           .Text = Text1.Text
           .Top = Text1.Top + Text1.Height + 200
           .Left = Text1.Left
           .Height = Text1.Height
           .Width = Text1.Width
           .Visible = True
        End With
    End Sub这样可以,呵呵
      

  4.   

    如果控件很多建议使用控件数组,然后通过load方法加载
    Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
        If KeyAscii = 13 Then
                Load Text1(Index + 1)
                With Text1(Index + 1)
                    .Visible = True
                    .Top = Text1(Index).Top + Text1(Index).Height + 10
                    .Left = Text1(Index).Left
                End With
        End If
    End Sub
      

  5.   

    这些都是在VB中使用的亚,哪在VBA中的具体操作又是怎么样的亚?
      

  6.   

    Dim btnObj As Control
    Public Sub NewTextBox(ByVal CtrlName As String)
        Set btnObj = Me.Controls.Add("Forms.TextBox.1", "TextBoxName")
        With btnObj
           .Text = Text1.Text
           .Top = 100
           .Left = 100
           .Visible = True
        End With
    End Sub
    Private Sub Text1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
      If KeyCode = 13 Then NewTextBox TxtCtrl
    End Sub