Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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

"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
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...