Insert text in the middle of a formated richtexbox.

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

Guest

I need to merge the content of two richtextboxes.

It can not be accomplished using the RichtTextBox.Text field because all
format will be lost. So it has to be done using the RichtTextBox.Rtf field,
but I loose part of it as follows:

private void MergeRtf()
{
// having the RichTextBox controls.

string Rtf = "";
int nInsertIndex = 50;
RichtTextBox1.SelectionStart = 0;
RichtTextBox1.SelectionLength = nInsertIndex;
Rtf = RichtTextBox1.Select
RichtTextBox1.Text = "";



}
 
Reposting this message.

I need to insert text into a richtextbox preserving the existing formating.

It can not be accomplished using the RichtTextBox.Text field because all
format will be lost. So, it has to be done using the RichtTextBox.Rtf field,
but I loose part of the content as follows:

private void MergeRtf()
{
// having the RichTextBox controls.

string sRtf = "";
string sInsert = "Insert this text";
int nInsertIndex = 50;
// Selecting richtext before inserting point
RichtTextBox1.SelectionStart = 0;
RichtTextBox1.SelectionLength = nInsertIndex;

// Adding richtext before inserting point to sRtf
sRtf = RichtTextBox1.SelectedRtf;

// Adding inserting text to sRtf
sRtf += sInsert;

// Selecting richtext After inserting point
RichtTextBox1.SelectionStart = nInsertIndex + 1;
RichtTextBox1.SelectionLength = RichtTextBox1.TextLength - nInsertIndex - 1;

// Adding richtext after inserting point to sRtf
sRtf += RichtTextBox1.SelectedRtf;

// Setting the RichTextBox.Rtf field, but it only adds the text before the
//inserting point.
RichtTextBox1.Rtf = sRtf;
}

I will appreciate any ideas.

Carlos Lozano
www.caxonline.net
 
Back
Top