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你怎么一个问题发了这么多遍!!
呵呵,既然楼主分多我就蹭了,再贴一次。'将Text1.ScrollBars = 3 - Both 、Text1.MultiLine = TruePrivate 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
限死你保证不出格Dim oldtext As String Const EM_LINEFROMCHAR = &HC9 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub Text1_Change() Linenum = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, Len(Text1.Text), 0) If Linenum > 5 Then Text1.Text = oldtext Else oldtext = Text1.Text End If End Sub
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你怎么一个问题发了这么多遍!!
呵呵,既然楼主分多我就蹭了,再贴一次。'将Text1.ScrollBars = 3 - Both 、Text1.MultiLine = TruePrivate 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
Const EM_LINEFROMCHAR = &HC9
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub Text1_Change()
Linenum = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, Len(Text1.Text), 0)
If Linenum > 5 Then
Text1.Text = oldtext
Else
oldtext = Text1.Text
End If
End Sub