Please help :( richtextbox issue

S

Sam

Hi,
I really don't understand why the following code set the font color of
'message' to blue but then when I type text manually in the richtextbox
after 'message', the font is still blue ! It should be black as I do
"\cf0}". Can anyone explain that to me ?

Dim message As String = "[" & DirectCast(lstFields.SelectedItem,
Field).FieldName & "]"
txtMessage.Rtf = "{\rtf1\ansi
{\colortbl;\red0\green0\blue0;\red0\green0\blue200;}" & txtMessage.Text
& "\cf2" & message & "\cf0}"
 
S

Sam

I've made some progress on this, but I still have an issue.
now I store my rtf stuff in a string and I assign the string at the
very end to the Rtf property of my richtextbox. It goes like this:

'rtf properties
Message.Append("{\rtf1\ansi
{\colortbl;\red0\green0\blue0;\red0\green100\blue200;}")

'Here I do plenty of checking. Basically the user can drag n drop an
item from a listbox to the richtextbox. This item must be written in
blue in the rtbox:

Message.Append("\cf2" & "[" & DirectCast(lstFields.SelectedItem,
Field).FieldName & "]" & "\cf0")

I use \cf0 so that the text entered by the user in the rtbox (after a
blue item) should be written in black

Finally I assign the string to the Rtf property:

txtMessage.Rtf = Message.ToString

You might have noticed that I did not close the } of the Rtf string.
Because otherwise it doesn't make sense as the user must be able to
type into the Rtbox (and as I said this text must appear in black)


An example of text in my rtbox:

<black> text entered by the user <\black> <blue> an item <\blue>
<black> some more text <\black>

The issue is that the text 'some more text' always appear in blue. So
as soon as I add an item, all text that follows appear in blue....


Why?
Can you help ?

Thx
 
S

Sam

argh please someone help with this, it's driving me crazy. Is my
problem not properly explained ? Or does nobody know how to solve this
?
 
S

Sam

I've actually noticed something interesting:

Message.Append("\cf2" & "[" & DirectCast(lstFields.SelectedItem,
Field).FieldName & "]" & "\cf0 ")

txtMessage.Rtf = Message.ToString

In this case txtMessage.Rtf is :

"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red0\green100\blue200;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs17 [testdeta]\cf0 fqwd\cf1
[tsetse]\cf0 ew \cf1 [testdeta]\par
}

Note the \par at the end instead of \cf0 !

If I do that :

Message.Append("\cf2" & "[" & DirectCast(lstFields.SelectedItem,
Field).FieldName & "]" & "\cf0 some text")

then txtmessage.Rtf is :
"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red0\green100\blue200;}
\viewkind4\uc1\pard\lang1033\f0\fs17 test\cf1 [tsetse ]\cf0 some
text\par
}
Note that I still have \par at the end, but at least the text that
follows my item is black, which is what I want. Now, since obviously I
don't want to add any hardcoded text after my item, how can I solve
this problem, and why the hell do I have a \par at the end instead of
\cf0 ?!?!!

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top