Box

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.
 
do it in keydown event.

set up an internal counter.
count to 100.
cancel all following keydowns until newline has been pressed.
reset counter.
 
You could do as heiko suggest, but when the counter reaches 100, automatically insert the carriage return and reset the counter.
 
I tried this code. Id does not work but I think it could with some help.

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