Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

How to autosize a textbox?

Hi,

I have a dialogform with just a textbox on it.
The textbox is set to dock=top and size.height
set to 13.

Every time I put a line of text into the textbox
then every line on top disappears.

How can I make the textbox autosize to its text?

Greetings,

Peter Kiers
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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
Avatar of Peter Kiers

ASKER

I have a panel with 2 textboxes on it. textBox1 is set to dock=top and textBox2 is set to dock=fill.
I have set this event for textBox1:

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                textBox2.Focus();

            }
        }

So the cursor goes from textBox1 to textBox2 after pressing the return-button.
But I want when the user starts typing in textBox1 and it reaches the end of the line
it then have to go to the nextline of the textBox1. And it doesn't.
How can I fixe this?

Peter
Keep your textboxes as Multiline text box where it accepts more than one line as input. Your code moves the focus to next textbox. This is contrary with your requirement. Remove it.
Both are set to MultiLine = true.
And I need the code because when the user presses enter in textBox1
it have to go to textbox2. Just the way I wanted.
Only in textbox1 the line of text has to go one to the second line
when the end of the textbox is reached.

Peter