Expandable Multiline TextBox

2 posts, 0 answers
  1. Garrett
    Garrett avatar
    1 posts
    Member since:
    Oct 2014

    Posted 06 Oct 2015 Link to this post

    Is there a way to expand... grab a corner and pull to "show more" when the control is full?

    Tried many searches for this... no luck.

  2. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 08 Oct 2015 Link to this post

    Hello Garett,

    Thank you for writing back.

    This type of functionality is not supported out of the box. You have, however, a couple of options which could help you in achieving a similar result. 

    You could build a complex layout in a RadSplitContainer, dock your textbox is some of the panels and use the splitters to resize it. This article could help you in creating the layout: Building Advanced Layouts. Another option is to make the control automatically resize when it is full with text. Please check my code snippet below as well as the attached gif file: 
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.CreateGrid(this.radSplitContainer1, 2, 2, Orientation.Horizontal, true);
     
            this.radTextBoxControl1.Multiline = true;
            this.radTextBoxControl1.TextBoxElement.VScrollBar.ValueChanged += VScrollBar_ValueChanged;
        }
     
        private void VScrollBar_ValueChanged(object sender, EventArgs e)
        {
            this.radTextBoxControl1.TextBoxElement.VScrollBar.Value = 0;
            this.radTextBoxControl1.Size = new Size(this.radTextBoxControl1.Size.Width + 5, this.radTextBoxControl1.Size.Height + 5);
        }
     
        private void CreateGrid(RadSplitContainer container, int cols, int rows, Orientation orientation, bool centerFill)
        {
            container.Orientation = orientation;
     
            for (int i = 0; i < rows; i++)
            {
                RadSplitContainer newContainer = new RadSplitContainer();
                newContainer.Orientation = Orientation.Vertical;
                newContainer.SizeInfo.AbsoluteSize = new Size(10, 10);
                for (int j = 0; j < cols; j++)
                {
                    SplitPanel panel = CreateSplitPanel();
                    panel.SizeInfo.AbsoluteSize = new Size(10, 10);
                    newContainer.SplitPanels.Add(panel);
                }
     
                container.SplitPanels.Add(newContainer);
            }
     
            if (centerFill)
            {
                SplitPanel centerPanel = (container.SplitPanels[rows / 2] as RadSplitContainer).SplitPanels[cols / 2];
                centerPanel.SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Fill;
                centerPanel.Controls.Add(new RadTextBoxControl() { Dock = DockStyle.Fill, Multiline = true });
            }
        }
     
        Random random = new Random();
        private SplitPanel CreateSplitPanel()
        {
            SplitPanel panel = new SplitPanel();
            Color back = Color.FromArgb(this.random.Next(155, 255), this.random.Next(155, 255), this.random.Next(155, 255));
            panel.SplitPanelElement.Fill.BackColor = back;
            panel.SplitPanelElement.Fill.GradientStyle = GradientStyles.Solid;
     
            return panel;
        }
    }

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

    Regards,
    Hristo Merdjanov
    Telerik

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top