Text Box Control

msappletech

Member
Joined
May 31, 2003
Messages
9
How do I limit the length of the lines in a text or rich text control in multiline mode to 100 characters. The functionality would be type 100 characters and then a carriage return type 100 characters and then carriage return.
This will limit the control to 100 characters. I only want to limit the lines in the control. The control will be able to accept as many characters as needed but the line will be limited to 100 chars.
 
Theres no built-in support for this. Can you handle it by using a single-line textbox that adds lines to a listbox?

If you want to handle it in one textbox, Id suggest using a regular expression. You can write an expression that finds matches on carriage return/line feed and limits the number of characters inbetween to 100. This wont prevent the user from typing more than 100 per line, but you could prevent them from saving (or leaving focus) until validated.

-Nerseus
 
Sorry here is the code.
Private Sub txtEdit_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEdit.TextChanged
Dim intLineNumber As Integer
intLineNumber = txtEdit.GetLineFromCharIndex(txtEdit.SelectionStart)
MsgBox(Len(txtEdit.Lines(intLineNumber).ToString))
If Len(txtEdit.Lines(intLineNumber).ToString) = 10 Then
txtEdit.Lines(intLineNumber) = txtEdit.Lines(intLineNumber) & vbCrLf
End If


End Sub
 
Back
Top