msappletech Posted June 4, 2003 Posted June 4, 2003 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. Quote
*Experts* Nerseus Posted June 5, 2003 *Experts* Posted June 5, 2003 There's 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, I'd 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 won't prevent the user from typing more than 100 per line, but you could prevent them from saving (or leaving focus) until validated. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
msappletech Posted June 5, 2003 Author Posted June 5, 2003 I tried this code and it does not work but I think it could if I had some help. Quote
msappletech Posted June 5, 2003 Author Posted June 5, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.