By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,844 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,844 IT Pros & Developers. It's quick & easy.

Insert text in the middle of a formated richtexbox.

P: n/a
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 = "";

}

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Carlos Lozano" wrote:
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 = "";

}

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.