appending to rtf string problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to build a test harness to practice appending strings to an rtf
string. I am doing this to simulate the string I'll be sending over the wire
and receiving on the other end of an IM application. Below is the code I use
to test.

I receive this error everytime I try to send the string from one rtb to
another:

"File Format is not valid Line 28" Line 28 is where I set rtb2 to the value
of the newly concatanated string----rtb2.Rtf =rtbBuild;



private void button1_Click(object sender, EventArgs e)
{
try
{


String msgCode = "101;";
String socketid = "2,";
String rtbVals = rtb1.Rtf.ToString();
String rtbBuild = msgCode + socketid + rtbVals;
rtb2.Rtf =rtbBuild;
}
catch (Exception excep)
{
MessageBox.Show(excep.ToString());
}

}



any ideas as to why I'm receivng this error? Thanks for any help!
 
Mike,

The reason this happens is because you are adding text to the rtf text
and trying to reassign it ot the Rtf property. Rtf is like Xml in the sense
that there are delimiters before and after the content, and you can't just
add something wherever you want in the string that makes up the RTF text.

What you need to do is strip away the message code and the socket id
before you set the Rtf property on the rich text box.


Hope this helps.
 
Back
Top