471,079 Members | 899 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,079 software developers and data experts.

Insert text in the middle of a formated richtexbox.

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
1 2507
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.

Similar topics

20 posts views Thread by akej via SQLMonster.com | last post: by
7 posts views Thread by tano | last post: by
2 posts views Thread by Nenad Dobrilovic | last post: by
3 posts views Thread by sb Luis | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.