473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving each line from a RichTextBox...

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

GetLineFromChar Index(RTB.TextL ength) 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
2 1598
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.RichText 1
.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.RichText 1.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********@mai l.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".

GetLineFromChar Index(RTB.TextL ength) 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
Thanks for that, Bob. I'd rather not use SendKeys, but if
all else fails I'll give it a go.

"Bob Hollness" <bo*@blockbuste r.com> wrote in message
news:ev******** *****@TK2MSFTNG P15.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.RichText 1
.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.RichText 1.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********@mai l.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".

GetLineFromChar Index(RTB.TextL ength) 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4028
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is displayed, effictively scrolling to the last line of the text box all the time. Can anyone help as I cannot seem to find a way to do this. Thanks
6
29232
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it scroll is with ScrollToCaret(). But I don't know how to set the "caret" to a particular line. Any suggestions? -Rachel
22
4549
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't that difficult, but to find the next line is more difficult. For exemple: if my cursor is on line 200, it has to start searching on line 201, and not on line 1. Anybody has any ideas?
4
8459
by: M O J O | last post by:
Hi, I'm using a RichTextBox with WordWrap=True and MultiLine=False. When the text is to long, it fills more lines. How do I get the number of lines the text uses? Thanks!
2
2447
by: Just Me | last post by:
I insert text in a RichTextBox ending each line with vbCrLf. I think when I search the RichTextBox text I do not find any CR's. In the Text property is the end of line char a LineFeed? Are the Cd's discared? What is it in a file?
0
4164
by: John Smith | last post by:
I have text files and I get binary offsets of text portion of these files from VB6 program with RichTextBox. I use VB.Net 2003 and need to select and highlight the text between given offsets. RichTextBox does not highlight the correct string as it treats new line pair as one character. Is there a way to highlight the correct string ? How do I translate real binary offsets to richtextbox offsets ? To reproduce: I have placed a text box...
0
1784
by: talon83 | last post by:
Ok, I am wondering how do I set the amount of characters per line that a richtextbox will have. I have a save dialog code and i want to set the characters to 64 characters then goto another line and save it like that. Right now when it saves a line of text, say 128 characters, it puts it all in 1 line. I would like it to split the line into two lines in the output .rtf file. ' Create a SaveFileDialog to request a path and file...
4
5979
by: Franky | last post by:
What I want to do is delete the last line in a RichTextBox. The RichTextBox has a ReadOnly property called lines that seems like it might help but I cant figure out how to use it. Well, the question is what is the easiest way to remove the last line in a RichTextBox? Thanks
2
2106
by: aemihal | last post by:
Hello, I have a RichTextBox that has a large number of lines, well in excess of the amount that can be seen without scrolling. Upon an event, such as clicking a button, I would like to move the viewable portion of the RichTextBox to be able to see that particular line. In other words, if the RichTextBox has 1000 lines of text, how can I force the viewable portion to start at, say, line number 123? This is what I have tried so far: ...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.