|
-
Sep 5th, 2005, 05:31 AM
#1
Thread Starter
New Member
Restrict the no. of characters in the Rich text box
Hi
I have a rich text box with multiline property set to yes. Now I want to restrict the max no. of characters that can be displayed in a line. what is the way ?
Shiva
-
Sep 5th, 2005, 05:44 AM
#2
Re: Restrict the no. of characters in the Rich text box
Is it acceptable to do this in the LostFocus event?
Do a loop through all the characters, counting as you go and resetting the count each time you come across a vbCr or vbLf (ASCII 13 and 10 respectively)
This world is not my home. I'm just passing through.
-
Sep 5th, 2005, 07:00 AM
#3
Thread Starter
New Member
Re: Restrict the no. of characters in the Rich text box
No it is not acceptable . if suppose i want to restrict the length to 25 cahracters and when the user enters the 26th character it has to automatically go to the next line or if a user deletes a charcter it has to rearrange.
 Originally Posted by trisuglow
Is it acceptable to do this in the LostFocus event?
Do a loop through all the characters, counting as you go and resetting the count each time you come across a vbCr or vbLf (ASCII 13 and 10 respectively)
-
Sep 5th, 2005, 10:34 AM
#4
Re: Restrict the no. of characters in the Rich text box
You can set the RightMargin property to force the RichTextBox to wrap the lines at this position. However the scale used for this property depends on the ScaleMode of the Form the RTB resides on and unless you use a mono-spaced font you can not set this to a certain amount of characters.
-
Sep 5th, 2005, 10:34 AM
#5
Re: Restrict the no. of characters in the Rich text box
how about using sendmessage something like this.
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_LINELENGTH = &HC1
Private Sub rtb_KeyPress(KeyAscii As Integer)
If SendMessage(rtb.hwnd, EM_LINELENGTH, rtb.SelStart, 0&) = 5 Then 'change the 5 to your number
rtb.Text = rtb.Text & vbCrLf
rtb.SelStart = Len(rtb.Text)
End If
End Sub
casey.
-
Sep 5th, 2005, 10:38 AM
#6
Re: Restrict the no. of characters in the Rich text box
@Casey: I was also thinking about the EM_LINELENGTH message but it won't work in the manner you have presented it with. In your code it will work if you're only adding text to the end of a document but not anywhere else. Let's say you already have 10 lines of text and you want to insert text on line 5. When that reach the limit of however many characters you want to use on a line your code will add a linebreak at end of the document and then jump to that position.
-
Sep 5th, 2005, 10:49 AM
#7
Re: Restrict the no. of characters in the Rich text box
Ahh !!, didnt think of that scenario. well spotted.
casey.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|