Contents of the RadRichTextBox

11 posts, 1 answers
  1. Stephen
    Stephen avatar
    45 posts
    Member since:
    Jul 2010

    Posted 15 Sep 2010 Link to this post

    Hi,

    I have two questions relating to the contents of a RadRichTextBox, maybe they belong in different threads but I figure I'll save some time and try to post them both here.

    1.  What is the best way to clear the contents of the RadRichTextBox?  I have tried recreating the associated document which does clear the contents but I get this weird issue where the control seems to create a large left and top margin.  The code is easily reproducable with:
     
    this.TextBox.Document = new RadDocument();

     

      

     

     

     

    I have also tried clearing the sections within document but this has no effect.

    2.  A common piece of input validation is to check that a control is not empty.  Is there an easy way to do this or will I need to write an extension method for the chosen format provider to do this?  For example I am using the XAML provider which contains alot of metadata about the document and various sections, but the user may not have entered any 'real' data, or just whitespaces and I need a way to pick this up.

    Stephen

     

  2. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 16 Sep 2010 Link to this post

    Hi Stephen,

    1. The way you have discovered for clearing the contents of a RadRichTextBox is indeed correct. The reason you're seeing large margins is because the default ones are optimized for printing. I'd recommend you to create a method to instantiate a new RadDocument for you and initialize it with your preferred settings. Another option would be to clear all the paragraphs in all the sections of the document (not all the sections since the margin is an attribute of the section), but I'd recommend the former.
    2. In any case, you'll have to implement this kind of checks yourself. There is no API since "real data" definition varies. One way would be to use the TxtFormatProvider to export the document to plain text and verify that against whatever checks you want. There might be others, but those will be much trickier and generally unnecessary.
    Don't hesitate to get back if you need any further assistance.

    Kind regards,
    Ivailo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Stephen
    Stephen avatar
    45 posts
    Member since:
    Jul 2010

    Posted 16 Sep 2010 Link to this post

    Hi Ivailo thanks for the response.

    In regards to clearing the text box.  How do I use the settings that it initially started with?  The reason being what I consider the 'default' document settings when a RadRichTextBox control is loaded is perfect to my needs.  I guess I could do a comparison or a deep copy of the document, but there must be some standard settings that are initialized in the RadRichTextBox that are not part of the RadDocument's default constructor initialization.

    Stephen
  4. Answer
    Alex
    Admin
    Alex avatar
    130 posts

    Posted 22 Sep 2010 Link to this post

    Hello Stephen,

    The RadDocument loaded by the RadRichTextBox is has indeed slightly different default settings than if you create a new instance of the RadDocument manually. Here is a method that setups RadDocument with the same settings as the rich text box:

    private RadDocument CreateDocument()
    {
        RadDocument doc = new RadDocument();
        doc.ParagraphDefaultSpacingAfter = 0;
        doc.PageViewMargin = new SizeF(0, 0);
        doc.SectionDefaultPageMargin = new Padding(6);
     
        return doc;
    }

    Please, get back to use if you need further help.

    Sincerely yours,
    Alex
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Vedran
    Vedran avatar
    6 posts
    Member since:
    Mar 2011

    Posted 14 Apr 2011 Link to this post

    Hi,
    This initialize method does not work, content of the document is not saved to the file system (when saving file manually).
    Any other solutions? :)
    tnx, Vedran
  6. Mike
    Admin
    Mike avatar
    640 posts

    Posted 14 Apr 2011 Link to this post

    Hello Vedran,

    Can you please try to give us more details about the problems you experience?

    Kind regards,
    Mike
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Vedran
    Vedran avatar
    6 posts
    Member since:
    Mar 2011

    Posted 10 May 2011 Link to this post

    Hi,
    The saved document simply has no content; it's blank.
    I used your initialization method, but the result is same.
    I cannot neither open that document again by using RadRichTextBox.
    I worked it out by making an empty RTF document (eg. using MS Word) and using it as a template for creating new documents (what is pretty bad programming practice).

    Tnx, Vedran
  8. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 13 May 2011 Link to this post

    Hello Vedran,

    I am not quite able to understand your case.
    The code form Alex's snippet shows how you can create a new blank document that has the same properties that RadRichTextBox sets on its default document. After you create this document, you can set it to the Document property of RadRichTextBox in the following way:

    this.radRichTextBox1.Document = CreateDocument();

    Saving the document using the format providers is an entirely new story. If you wish to save the document, without showing it in a rich text box, you need to measure and arrange the document in advance. Please refer to the code-snippet below:
    RadDocument document = new RadDocument();
    //Set some properties, add Blocks (Paragraphs and Tables), etc.
    MeasureAndArrangeInDefaultSize(document);
    //Export
     
    private void MeasureAndArrangeInDefaultSize(RadDocument document)
    {
        document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
        document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
    }

    If this does not answer your question, we would really appreciate some more detailed information on your scenario.

    Regards,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Vedran
    Vedran avatar
    6 posts
    Member since:
    Mar 2011

    Posted 18 May 2011 Link to this post

    Yeah, magic words... measure & arrange :)) tnx!
  10. Dave
    Dave avatar
    39 posts
    Member since:
    Jun 2008

    Posted 31 Oct 2011 Link to this post

    sigh... nevermind
  11. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 01 Nov 2011 Link to this post

    Hi Dave,

    In the latest versions of the control (starting from the Q2 official release - 2011.2.712) we have decided to invoke these operations internally whenever needed. Therefore, it will not be necessary to invoke them on your end.
    If you have found a case when they need to be invoked explicitly as in the snippet, we would appreciate your feedback in order to fix the lapse.

    Regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top