Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox Line length limiting

Status
Not open for further replies.

robdon

Programmer
May 21, 2001
252
ES
Hi,

Does any one know of any coding example that would limit all lines in a RichTextBox to a certain length (number of chars), and also possibly to 'autowrap' the last word to the next line if inserting more than X chars?

I basically need the RightMargin property, but in characters rather than width/pixels/twips.

Thanks,

Rob D.
 
robdon,

This very basic code should give you the idea. The number 20 limits the number of characters in the line. This is not the final code, just idea. There is no 'autowrap' feature in this example.

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
With RichTextBox1
If (Len(.Text) Mod 20) = 0 Then
KeyCode = vbKeyReturn
End If
End With
End Sub

Vladk
 
Sadly, I don't think that's really going to help at all (apart from in a very, very limited case)...
 
Strongm,
This was just an idea that should explain that manipulation with Len and Mod could produce some usefull output regarding this problem.

I suspect,your proposition would be API calls?

VladK
 
Hi,

Thanks for the example, but I know the basics... just wondered if there was some API or something that might help, or some example if someone had already done it.

It needs to cope with Pasting, joining lines etc.

Rob D.
 
robdon,

given that any character on any line in an RTB can be any size, just how do anticipate that there can be a reliable method of setting line width based on character size?
 
Maybe I didnt explain it well enough....

Its not the line width that I want to set, its the fact that each line in the RTB can only have a max of 'x' number of characters on it.

My app has a RTB box that allows the user to enter any text. I need to save that text back to a database that has 1 record for each line, and the column that holds the line has a max length of 80 charaters. I cannot change the DB column size, so I have to limit the RTB to only 80 chars per line.

Rob D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top