|
-
Nov 12th, 2018, 01:57 PM
#1
Thread Starter
Junior Member
Locate Wrapped Words in a RichTextBox
My project is using a large font and I am trying to locate any words in a multiline RTB w/wordwrap that do not fit on one line. I did a char dump of the Rtb.text and there is no LFs or CRs. Is it possible to locate automatic word wraps in a RTB?
For example if I have
"This document has one ReallyReallyLongWord so I need to find it."
With my large font I will see something like this at runtime
This document
has one
ReallyReallyLon
gWord so I need
to find it.
I need to locate words that do not fit on a single line so I can later reduce the font size of just that word.
How can I find wrapped words?
Thanks for any help.
-
Nov 12th, 2018, 02:04 PM
#2
Re: Locate Wrapped Words in a RichTextBox
you can try the GetPositionFromCharIndex property of the richtextbox and work out intentional (cr+lf) and generated wraps.
-
Nov 12th, 2018, 02:21 PM
#3
Thread Starter
Junior Member
Re: Locate Wrapped Words in a RichTextBox
My rtb.text doesn't have any hard CR+LF characters and the auto word wrap feature doesn't seem to add any to the rtb.text. I was hoping there was some way to locate the soft wraps but I cant find anything.
Expanding on your GetPositionFromCharIndex……. Is there a way to get what line a single character is on? I could try to look at every character between spaces and see if they are all on the same line number. Painful to do but as a last resort I could try that.
-
Nov 12th, 2018, 02:27 PM
#4
Thread Starter
Junior Member
Re: Locate Wrapped Words in a RichTextBox
I did a little digging after my post and it looks like this will get me the line number of a char TextBoxBase.GetLineFromCharIndex. But I am still hoping there is a soft wrap character somewhere I can look for?????
-
Nov 12th, 2018, 05:06 PM
#5
Thread Starter
Junior Member
Re: Locate Wrapped Words in a RichTextBox
Thanks for the help. This is what I worked out. Haven't debugged it or checked to see if I can simplify it but a quick test and it finds the word wrap.
Code:
Dim i As Integer
Dim iWordStart As Integer = 1
Dim iWordEnd As Integer = 1
Dim iLastLine As Integer
For i = 1 To RichTextBox1.TextLength
If GetChar(RichTextBox1.Text, i) = " " Then
'Reset the word pointers
iWordStart = iWordEnd
iWordEnd = i
'Reset the line pointer
iLastLine = RichTextBox1.GetLineFromCharIndex(i)
Else
If iLastLine <> RichTextBox1.GetLineFromCharIndex(i) Then
'This word is wrapped
iWordStart = iWordEnd
RichTextBox1.SelectionStart = iWordStart
Do
If GetChar(RichTextBox1.Text, i) = " " Then
iWordEnd = i - 1
RichTextBox1.Select(iWordStart, iWordEnd - iWordStart)
Exit For
End If
i = i + 1
Loop Until i >= RichTextBox1.TextLength
End If
End If
Next
Tags for this Thread
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
|