如何限定多行文本框只能输入6行(并非最大字符数.)
如回车可换行,最大行数为6行,而不是最大字符数.

解决方案 »

  1.   

    用InStr查找回车键的个数......
      

  2.   

    if InStr(1, Text1.Text, vbCrLf)>=6 then
      

  3.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Dim strAry() As String
        
        If KeyAscii = vbKeyReturn Then
            strAry = Split(Text1.Text, vbCrLf)
            If UBound(strAry) > 4 Then
                KeyAscii = 0
                MsgBox "对不起,只允许输入6计"
            End If
        End If
    End Sub
      

  4.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Dim strAry() As String
        
        If KeyAscii = vbKeyReturn Then
            strAry = Split(Text1.Text, vbCrLf)
            If UBound(strAry) > 5 Then
                KeyAscii = 0
            End If
        End If
    End SubPrivate Sub Text1_change()
        Dim strAry() As String
        
            strAry = Split(Text1.Text, vbCrLf)
            If UBound(strAry) > 5 Then
                  msgbox "不允许超过6行!"'
            End If
    End Sub
      

  5.   

    '将Text1.ScrollBars = 3 - Both  、Text1.MultiLine = True
    Private Sub Text1_Change()
    Dim strAry() As String
    Dim mTempA As String
        strAry = Split(Text1.Text, vbCrLf)
        If UBound(strAry) > 5 Then
            Text1.SelStart = Len(strAry(0) & strAry(1) & strAry(2) & strAry(3) & strAry(4) & strAry(5)) + 10
            Text1.SelLength = Len(Text1.Text) - Len(strAry(0) & strAry(1) & strAry(2) & strAry(3) & strAry(4) & strAry(5))
            SendKeys "{BackSpace}"
        End If
    End Sub