Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SelRTF and Richtextboxes

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
Hello all,
I'm at work on a client that features a richtextbox, I need a function that will append a line of RTF code to the end of the current one.

The only way I've found that works is to take a copy of .TextRTF and then cut off the ending ("}" & vbcrlf) and then add my stuff, add the ending and drop it back into .TextRTF.

I fear however, taht when the chatbox becomes very full this operation will take longer, and longer and longer.

So, I figure by my best estimate that I need to use .SelRTF instead, but I've run into a problem with that. When I place the cursor location in the proper area, and then add code it seems to either fail to use code words, or it negates them. For example "\bTest\b0" just doesn't work, nothing simply happens. Its as if the selrtf property was never set. or if i try just "Test\par" to end the current line, It inserts "\\par" which doesn't end the line and shows up as text.

So my question is, Does anyone know of a fast and effecient way to drop a line of formated RTF to the end of a Richtextbox.
 
In a quick break between breakfasting on scrambled eggs with smoked salmon and a present opening frenzy I offer the following:

This is because "\bTest\b0" is not fully-formed RTF, which is what the SelRTF expects to be given.

The way around this is to use a second RichTextBox. Place your text in there. Apply the required formatting to the text there, then add the .SelRTF from box2 to box1

e.g.
[tt]
RichTextBox2.Text = "Test"
RichTextBox2.SelStart = 0
RichTextBox2.SelLength = 63635
RichTextBox2.SelBold = True ' Apply required formatting
RichTextBox1.SelStart = 63635 ' Quick way to move to end
RichTextBox1.SelRTF = RichTextBox2.SelRTF
 
strongm,
Was that an uncharacteristic typo I just saw?

63635 (= &HF893

I was expecting
65535 (= &HFFFF)

If so I'll put it down to the stress of oeufs benedict!

Seasons Greetings to you all

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Quite so. I was/am celebrated out, and therefore prone to quite stupendous errors (such as wearing a santa clause hat to the pub earlier...)
 
Thank you very much for the replies, the reason I'm not using .SelBold and such is because in the terms of the project this is not feasible. What I'm having trouble with is, the fact that I can in fact use examples from the microsoft RTF whitepaper, and it ends up changing it around on me. This is not what I'm grasping, but I guess I'm just missing some minor detail, I guess there is no quick & easy solution so I shall just continue to reread and work with the RTF whitepaper.

 
If you could perhaps explain why this isn't feasible, perhaps we could offer other options.

It is also worth pointing out that the RichTextBox control included with VB is an implementation of the rich edit control version 1.0 (as originally released with Windows 95), which is somewhat limited in it's capabilities compared to the current version shipping version of the rich edit control (version 4.1 with XP SP1). As a result, there are numerous rich text control words that it does not understand and will, as a result, discard as it parses them in.
 
The reason I'm attempting to avoid using the selbold and selitalics is because the line of text being added is formatted and set up by users. Its also inaccurate in my attempts of implementation, but perhaps I just wasn't looking at it right, so I'll try to eleborate. For reference, a // indicateds the starting or stopping of italics, and \\ is bold.

If we have:
"The quick //brown// fox.."
Thats very simple and easy to pick up, we remove the "//" and note their positions and set the appropiate selbold spots.

But when we have:
"The //very// quick //brown// fox.."
Its still very doable, we just have to add some math in to compensate for the missing characters [the removed //'s results in different italics locations.]

And when we finally get sentances like:
"The //very// quick //brown// fox jumped \\over\\ the //lazy// dog."
The math and associated loops got to convuluted and skewed.

I was hoping to just use selrtf because it would be much easier, because I would just change the string around before passing it to selrtf, But my knowledge of RTF and the Richtextboxes inheriant sketchyness [such as a bad .selrtf sometimes causes a GPF..ouch] has moved me to at least temporarily look into a better solution.

I'm considering using a webbrowser to display the output, but I'm having trouble gaining controller over its scrollbar, but I suppose its possible.

I do however, thank you all very much for your consideration and time that you've put into my problem. If you have any suggestions or comments, I'd love to hear them.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top