This is a migrated thread and some comments may be shown as answers.

Rich Textbox like MS Word view

6 Answers 178 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Thomas
Top achievements
Rank 1
Thomas asked on 09 Mar 2011, 07:53 PM
Hello:

I am new to Telerik.
I would like to open RichTextbox like a MS word in a popup window and load .doc and .docx into it.
Kindly guide me.


Thank you
Tom

6 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 15 Mar 2011, 04:28 PM
Hello Thomas,

There is a demo of a MS Word-like use of the rich text box together with the ribbon at http://demos.telerik.com/silverlight/beta/#RichTextBox/MSWord. You can view the code used for creating the demo by clicking "View code" in the top-right corner. This example is also included in the sample projects which are included in the installation zips. You can download it from your account.
Import from and export to doc are currently not supported and have not been scheduled, i.e. it has yet to be determined if and when they will be implemented. For a list of the available file formats, you can refer to this help article.
If we can help you with anything else, do not hesitate to get back to us.

Kind regards,
Iva
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Thomas
Top achievements
Rank 1
answered on 17 Mar 2011, 08:05 PM
Thank you for your reply.
Where can I find the stand alone MSword example for silverlight RadRichtextbox?

Also I would like to build a letter (like an email) dynamically inside the RadRichtextbox (which looks like a MS word). Kindly guide me to an example.

Thank you in advance for your reply.
Tom

0
Iva Toteva
Telerik team
answered on 23 Mar 2011, 12:10 PM
Hi Thomas,

Please find attached a stand-alone MsWord example of the rich text box for Silverlight. It pretty much copies the code from the examples, included in the installation for Q1 2011 (2011.1.315).
As for dynamically building the content of document, that can be done through RadRichTextBox's and RadDocument's API. This forum thread deals exclusively with code-behind manipulation of the document before it is shown in a rich text box. There is also a small demo in one of the first posts, that can help you get started. Basically, you can manipulate the Children/ Inlines/ Blocks properties of the different document elements before the document is measured and arranged (which happens once the document is shown in the editor). After that, you can use the methods from the API (InsertInline(), Insert(), etc.).

All the best,
Iva
the Telerik team
0
Thomas
Top achievements
Rank 1
answered on 24 Mar 2011, 12:01 PM

Hi Iva:

Thank you. That was very helpfull. I have used following code to generate document code. But it doesnt seem to render rightly.
Is this approach is correct?

======================================================================
  RadDocument doc = new RadDocument();
                doc.LayoutMode = DocumentLayoutMode.Paged;

                Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
                doc.Sections.Add(section);

                doc.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(50, 50, 50, 50);

                ///Build To Address
                Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
                section.Blocks.Add(paragraph);

                Telerik.Windows.Documents.Model.Span spanTo = new Telerik.Windows.Documents.Model.Span();
                spanTo.FontSize = 10;
                spanTo.Text = "To," + "\r\n";
                paragraph.Inlines.Add(spanTo);   
               

                Telerik.Windows.Documents.Model.Span spanRefPhy = new Telerik.Windows.Documents.Model.Span();
                spanRefPhy.FontSize = 10;
                spanRefPhy.Text = referringPhysician + "\r\n";
                paragraph.Inlines.Add(spanRefPhy);  

                Telerik.Windows.Documents.Model.Span orgName = new Telerik.Windows.Documents.Model.Span();
                orgName.FontSize = 10;
                orgName.Text = relatedOrganisationObj.related_organization_name + "\r\n";
                paragraph.Inlines.Add(orgName);            

                Telerik.Windows.Documents.Model.Span addLine1 = new Telerik.Windows.Documents.Model.Span();
                addLine1.FontSize = 10;
                addLine1.Text = relatedOrganisationObj.address_line_1 + "\r\n";
                paragraph.Inlines.Add(addLine1);

                if (relatedOrganisationObj.address_line_2 != null)
                {
                    Telerik.Windows.Documents.Model.Span addLine2 = new Telerik.Windows.Documents.Model.Span();
                    addLine2.FontSize = 10;
                    addLine2.Text = relatedOrganisationObj.address_line_2 + "\r\n";
                    paragraph.Inlines.Add(addLine2);
                }
                if (relatedOrganisationObj.city != null)
                {
                    Telerik.Windows.Documents.Model.Span city = new Telerik.Windows.Documents.Model.Span();
                    city.FontSize = 10;
                    city.Text = relatedOrganisationObj.city +" " + relatedOrganisationObj.state_code + "\r\n";
                    paragraph.Inlines.Add(city);
                }
           
                if (relatedOrganisationObj.zip_code != null)
                {
                    Telerik.Windows.Documents.Model.Span zipCode = new Telerik.Windows.Documents.Model.Span();
                    zipCode.FontSize = 10;
                    zipCode.Text = relatedOrganisationObj.zip_code + "\r\n";
                    paragraph.Inlines.Add(zipCode);
                }
                //End of Build Too Address

 

              

                Telerik.Windows.Documents.Model.Span spanFrom = new Telerik.Windows.Documents.Model.Span();
                spanFrom.FontSize = 10;
                spanFrom.Text = "From," + "\r\n";
                paragraph.Inlines.Add(spanFrom);

                Telerik.Windows.Documents.Model.Span docName = new Telerik.Windows.Documents.Model.Span();
                docName.FontSize = 10;
                docName.Text = "Dr." + App.global_user.first_name + App.global_user.last_name + "\r\n";
                paragraph.Inlines.Add(docName);

                Telerik.Windows.Documents.Model.Span orgName2 = new Telerik.Windows.Documents.Model.Span();
                orgName2.FontSize = 10;
                orgName2.Text = facilityObj.facility_name + "\r\n";
                paragraph.Inlines.Add(orgName2);

                Telerik.Windows.Documents.Model.Span addLine12 = new Telerik.Windows.Documents.Model.Span();
                addLine12.FontSize = 10;
                addLine12.Text = facilityObj.address_line_1 + "\r\n";
                paragraph.Inlines.Add(addLine12);

                if (facilityObj.address_line_2 != null)
                {
                    Telerik.Windows.Documents.Model.Span addLine22 = new Telerik.Windows.Documents.Model.Span();
                    addLine22.FontSize = 10;
                    addLine22.Text = facilityObj.address_line_2 + "\r\n";
                    paragraph.Inlines.Add(addLine22);
                }
                if (facilityObj.City != null)
                {
                    Telerik.Windows.Documents.Model.Span city2 = new Telerik.Windows.Documents.Model.Span();
                    city2.FontSize = 10;
                    city2.Text = facilityObj.City + "\r\n";
                    paragraph.Inlines.Add(city2);
                }
                if (facilityObj.state_code != null)
                {
                    Telerik.Windows.Documents.Model.Span stateCode2 = new Telerik.Windows.Documents.Model.Span();
                    stateCode2.FontSize = 10;
                    stateCode2.Text = facilityObj.state_code + "\r\n";
                    paragraph.Inlines.Add(stateCode2);
                }
                if (facilityObj.zip_code != null)
                {
                    Telerik.Windows.Documents.Model.Span zipCode2 = new Telerik.Windows.Documents.Model.Span();
                    zipCode2.FontSize = 10;
                    zipCode2.Text = facilityObj.zip_code + "\r\n";
                    paragraph.Inlines.Add(zipCode2);
                }

                radRichTextBox.Document = doc;  

0
Accepted
Iva Toteva
Telerik team
answered on 29 Mar 2011, 08:45 AM
Hi Thomas,

You can not have carriage returns ("\r") and symbols for new line ("\n") in the Text of a Span. The combination "\r\n" is used to separate different paragraphs and the document structure becomes invalid when you add them to the text of spans.
In order to achieve the result you are looking for, you should create different paragraphs and add them to the Section's Blocks property instead of adding them as spans to one paragraph.
Here is a sample code illustrating the approach:

private RadDocument BuildDocument()
{
    RadDocument doc = new RadDocument();
    doc.LayoutMode = DocumentLayoutMode.Paged;
    Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
    doc.Sections.Add(section);
    doc.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(50, 50, 50, 50);
 
    ///Build To Address
    Telerik.Windows.Documents.Model.Paragraph paragraphTo = CreateParagraphWithText("To,");
    section.Blocks.Add(paragraphTo);
 
    Telerik.Windows.Documents.Model.Paragraph paragraphRefPhy = CreateParagraphWithText(referringPhysician);
    section.Blocks.Add(paragraphRefPhy);
 
    Telerik.Windows.Documents.Model.Paragraph orgName = CreateParagraphWithText(relatedOrganisationObj.related_organization_name);
    section.Blocks.Add(orgName);
 
    Telerik.Windows.Documents.Model.Paragraph addLine1 = CreateParagraphWithText(relatedOrganisationObj.address_line_1);
    section.Blocks.Add(addLine1);
 
    if (relatedOrganisationObj.address_line_2 != null)
    {
        Telerik.Windows.Documents.Model.Paragraph addLine2 = CreateParagraphWithText(relatedOrganisationObj.address_line_2);
        section.Blocks.Add(addLine2);
    }
 
    if (relatedOrganisationObj.city != null)
    {
        Telerik.Windows.Documents.Model.Paragraph city = CreateParagraphWithText(relatedOrganisationObj.city + " " + relatedOrganisationObj.state_code);
        section.Blocks.Add(city);
    }
    //...
    return doc;
}
 
private Telerik.Windows.Documents.Model.Paragraph CreateParagraphWithText(string text, double fontSize = 10)
{
    Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
    Telerik.Windows.Documents.Model.Span span = new Telerik.Windows.Documents.Model.Span();
    span.Text = text;
    span.FontSize = fontSize;
    paragraph.Inlines.Add(span);
    return paragraph;
}

I hope that helps.

All the best,
Iva
the Telerik team
0
Thomas
Top achievements
Rank 1
answered on 31 Mar 2011, 04:17 PM
Thank you So much.
Tom
Tags
RichTextBox
Asked by
Thomas
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or