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

Autosize

1 Answer 117 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
konrad
Top achievements
Rank 1
konrad asked on 16 Jun 2015, 06:38 AM

Hello,

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?

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 18 Jun 2015, 02:48 PM
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()
    {
        InitializeComponent();
        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.

Regards,
Hristo Merdjanov
Telerik
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
Tags
RichTextEditor
Asked by
konrad
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or