-
Mar 16th, 2015, 06:56 AM
#1
[RESOLVED] RTF File to richtextboxes
Ok, my turn to play dumb....
I have an rtf file something like this small example:
Code:
GEOGRAPHY
Europe
Asia
Australia
I know I can use the loadfile or Input functions to load the entire file into ONE richtextbox,
as in:
Code:
Dim intFile As Integer
intFile = FreeFile
Open App.Path & "\myrtffile.rtf" For Input As intFile
RichTextBox1.TextRTF = StrConv(InputB$(LOF(1), 1), vbUnicode)
Close intFile
but ....
I want to load each line separately into richtextboxes (this example, 4) and retain the formatting (color/underlined/Etc).
Simple example?
-
Mar 16th, 2015, 07:48 AM
#2
Re: RTF File to richtextboxes
You'll still need the initial RichTextBox to read and interpret the Rich Text File, then slice it up into individual lines from there.
Try opening your Rich Text File in Notepad.
It doesn't look anything like what you posted; all that "stuff" in there is the RichText markup that makes RichText what it is. (If you really want to scare yourself, try the same with an old-style .doc file!). You don't want to try making sense of all that yourself - there's a handy little Control available to do all that for you; the RichTextBox.
Of course, that doesn't mean that your Users need to see this intermediate RichTextBox; it works just as well with its Visible property set to False.
Regards, Phill W.
-
Mar 16th, 2015, 07:55 AM
#3
Re: RTF File to richtextboxes
The issue you'll have trying to do this line by line, is that the current line you are reading may have been formatted by RTF codes that were read much earlier in the file. I think you'd have to keep track of those and apply it to each line you read, but that is oversimplifying the process. Phil's solution may be the easiest
-
Mar 16th, 2015, 08:19 AM
#4
Re: RTF File to richtextboxes
You'll still need the initial RichTextBox to read and interpret the Rich Text File, then slice it up into individual lines from there.
So, you mean first load the file into a RTB (which can be invisible), then use functions like SelStart, SelLength and SelText to load each 'line' into other RTBs? Sounds like a pain...but guess that must be the best solution.
--ps--yeah, I know about all that other 'stuff' when opening an rtf file in NotePad---of course, in Word, it 'appears' the way I want to see each line in separate RTBs.
-
Mar 16th, 2015, 08:21 AM
#5
Re: RTF File to richtextboxes
The issue you'll have trying to do this line by line, is that the current line you are reading may have been formatted by RTF codes that were read much earlier in the file.
I see what you mean. If first two 'lines' are bold and underlined, and try to get just the first line, it won't have the formatting characters at the beginning and ending.
Guess I'll play around with Phil's advice.
-
Mar 16th, 2015, 10:40 AM
#6
Re: [RESOLVED] RTF File to richtextboxes
Use the SelRtf property instead of SelText, and you should get all the formatting in your second RichTextBox.
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
|