Append document from one control to another

2 posts, 1 answers
  1. Abraham
    Abraham avatar
    2 posts
    Member since:
    Sep 2012

    Posted 12 Mar 2013 Link to this post

    I have two Telerik rich text boxes in my winforms application. I am trying to append the formatted text from one of the rich textboxes to all areas where a predefined section in the first rich textbox. 

    The below code works for finding the required predefined  sections - Once this is done, There was an option to insert a text but I couldnt find anything where I could insert the formatted text. 

    radRichTextBox1.Document.Selection.Clear();

     

    DocumentTextSearch search = new DocumentTextSearch(radRichTextBox1.Document);

     

    foreach (var textRange in search.FindAll("Section1"))

    {

    radRichTextBox1.Document.Selection.AddSelectionStart(textRange.StartPosition);

     

     

    this.radRichTextBox1.Document.Selection.AddSelectionEnd(textRange.EndPosition);

    // what to do here to insert the formattted text from radRichTextBox2

    }

  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 13 Mar 2013 Link to this post

    Hi Abraham,

    Thank you for writing.

    Here is how you can append (insert) the selected formatted text from the first RadRichTextBox control to the sections that you want in the second control:
    private void radButton1_Click(object sender, EventArgs e)
    {
        DocumentFragment selectedFragment = radRichTextBox1.Document.Selection.CopySelectedDocumentElements();
     
        DocumentTextSearch search = new DocumentTextSearch(radRichTextBox2.Document);
        foreach (var textRange in search.FindAll("RichTextBox"))
        {
            radRichTextBox2.Document.CaretPosition.MoveToPosition(textRange.EndPosition);
            radRichTextBox2.Document.InsertFragment(selectedFragment);
        }
    }

    I hope that you find this information useful.
     

    Regards,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top