By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Retrieving each line from a RichTextBox...

P: n/a
....without resorting to SendMessage. Imagine, for example,
I have a small RTB whose text has wrapped as follows:

"This is a small test to see if I can get"
"both of these lines".

GetLineFromCharIndex(RTB.TextLength) returns 1, telling me
there are two lines in there. Using the Lines property to
retrieve them will fail, however. As the line has
soft-wrapped (i.e. the user has not hit Enter after "get"),
it returns "This is a small test to see if I can get both of
these lines".

In VB6, SendMessage would come to the rescue here. Is there
a managed way of achieving the same thing?
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Not sure if this helps, but........

I used this in VBA, it might come in handy. It does exactly what you want.
You would just need to translate it. (sorry!)

Function GetLines() As Variant
Dim lLines As Long
With MyForm.RichText1
.SetFocus
lLines = .LineCount
End With

ReDim arrTmp(lLines) As String
For X = 1 To lLines
'Set and select linenumber
SetLine X
'pick up text in line
arrTmp(X) = n
Next
'return values to function
GetLines = arrTmp
Erase arrTmp

End Function

Sub SetLine(ByVal LineNumber As Integer)
On Error Resume Next
'set linenumber
MyForm.RichText1.CurLine = LineNumber - 1
'make selection using sendkeys (argghh)
SendKeys "{HOME}", -1
SendKeys "+{END}", -1
If Err <> 0 Then Err.Clear
End Sub

--

Bob

--------------------------------------
I'll have a B please Bob.

"Mark Raishbrook" <ra********@mail.telepac.pt> wrote in message
news:41**********************@news.telepac.pt...
...without resorting to SendMessage. Imagine, for example,
I have a small RTB whose text has wrapped as follows:

"This is a small test to see if I can get"
"both of these lines".

GetLineFromCharIndex(RTB.TextLength) returns 1, telling me
there are two lines in there. Using the Lines property to
retrieve them will fail, however. As the line has
soft-wrapped (i.e. the user has not hit Enter after "get"),
it returns "This is a small test to see if I can get both of
these lines".

In VB6, SendMessage would come to the rescue here. Is there
a managed way of achieving the same thing?

Nov 21 '05 #2

P: n/a
Thanks for that, Bob. I'd rather not use SendKeys, but if
all else fails I'll give it a go.

"Bob Hollness" <bo*@blockbuster.com> wrote in message
news:ev*************@TK2MSFTNGP15.phx.gbl...
Not sure if this helps, but........

I used this in VBA, it might come in handy. It does
exactly what you want. You would just need to translate
it. (sorry!)

Function GetLines() As Variant
Dim lLines As Long
With MyForm.RichText1
.SetFocus
lLines = .LineCount
End With

ReDim arrTmp(lLines) As String
For X = 1 To lLines
'Set and select linenumber
SetLine X
'pick up text in line
arrTmp(X) = n
Next
'return values to function
GetLines = arrTmp
Erase arrTmp

End Function

Sub SetLine(ByVal LineNumber As Integer)
On Error Resume Next
'set linenumber
MyForm.RichText1.CurLine = LineNumber - 1
'make selection using sendkeys (argghh)
SendKeys "{HOME}", -1
SendKeys "+{END}", -1
If Err <> 0 Then Err.Clear
End Sub

--

Bob

--------------------------------------
I'll have a B please Bob.

"Mark Raishbrook" <ra********@mail.telepac.pt> wrote in
message news:41**********************@news.telepac.pt...
...without resorting to SendMessage. Imagine, for
example,
I have a small RTB whose text has wrapped as follows:

"This is a small test to see if I can get"
"both of these lines".

GetLineFromCharIndex(RTB.TextLength) returns 1, telling
me
there are two lines in there. Using the Lines property to
retrieve them will fail, however. As the line has
soft-wrapped (i.e. the user has not hit Enter after
"get"),
it returns "This is a small test to see if I can get both
of
these lines".

In VB6, SendMessage would come to the rescue here. Is
there
a managed way of achieving the same thing?


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.