Link to home
Start Free TrialLog in
Avatar of greep
greep

asked on

C# Windows app. Increase the height of a multiline textbox to show all text entered

Hi

I am new to C# so apologies if this is a silly question.

I have a windows form with a series of textboxes for data input.  A few of them are multiline.  I need to expand the height of the multiline text box to show all the data that has been input without a scrollbar.

I will also need to move all the controls below the adjusted text box down the form to a new position to avoid overlap.

Any sample code or help would be great!

Thanks in advance!
Avatar of ghayasurrehman
ghayasurrehman
Flag of Pakistan image

set textbox property textBox1.Multiline = True

just drag and drop your controls where you want
Avatar of kris_per
kris_per


One option is to use 'TableLayoutPanel' in the designer which will automatically push the controls down.
Add a TableLayoutPanel to the form in the designer.
Arrange the textboxes and other controls in the rows of that table.
when you increase the height of a multiline textbox, increase the height of the table row as well (like tableLayoutPanel1.RowStyles[i].Height += 30). This will automatically push all the controls in the rows below down.

Another option is to programatically change the Location of the controls as shown in the code below.

public void MoveControlsBelow(Control control, int moveHeight)
        {
            foreach (Control c in this.Controls)
            {
                if (c != control)
                {
                    if (c.Location.Y >= control.Location.Y)
                    {
                        c.Location = new Point(c.Location.X, c.Location.Y + moveHeight);
                    }
                }
            }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kris_per
kris_per

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with Kris per's solution. That is the best answer.

Regards,
VSS
Avatar of greep

ASKER

Thanks!  Much appreciated!