2 posts, 0 answers
  1. Dominik
    Dominik avatar
    59 posts
    Member since:
    Dec 2012

    Posted 16 Jun 2015 Link to this post


    I have user control (AutoSize = True) with RichTextEditor inside. 

    I want to force RichTextEditor to show all content all the time.

    First when user enter text, it should not show VerticalScroll when user put to many lines. The control should re-size automatically (only Height should change).

    Secondly, when I import content to RichTextEditor, it should automatically calculate size of document and make whole content visible.

    Is that possible?

  2. Hristo Merdjanov
    Hristo Merdjanov avatar
    660 posts

    Posted 18 Jun 2015 Link to this post

    Hi Dominik,

    Thank you for writing.

    You can achieve the desired behavior by handing two events, TextChanged - so that the control resizes as you type, and DocumentChanged - in order to calculate its new height according to the imported document. Please see my code snippet below: 
    public partial class Form1 : Form
        public Form1()
            this.radRichTextEditor1.DocumentChanged += radRichTextEditor1_DocumentChanged;
            this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBarVisibility = Telerik.WinControls.RichTextEditor.UI.ScrollBarVisibility.Hidden;
            this.radRichTextEditor1.TextChanged += radRichTextEditor1_TextChanged;
        private void radRichTextEditor1_TextChanged(object sender, EventArgs e)
            this.radRichTextEditor1.Height = (int)this.radRichTextEditor1.RichTextBoxElement.Document.Children.First.BoundingRectangle.Height;
        private void radRichTextEditor1_DocumentChanged(object sender, EventArgs e)
            this.radRichTextEditor1.Height = (int)this.radRichTextEditor1.Document.Sections.First().PageSize.Height;
        private RadDocument ImportDocx()
            RadDocument document = null;
            IDocumentFormatProvider provider = new DocxFormatProvider();
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Documents|*.docx";
            openDialog.Multiselect = false;
            DialogResult dialogResult = openDialog.ShowDialog();
            if (dialogResult == System.Windows.Forms.DialogResult.OK)
                using (Stream stream = openDialog.OpenFile())
                    document = provider.Import(stream);
            return document;
        private void radButton1_Click(object sender, EventArgs e)
            this.radRichTextEditor1.Document = this.ImportDocx();

    I am also sending you a gif file showing the result on my end. 

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Hristo Merdjanov
    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 Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top