Solved

How to autosize a textbox?

Posted on 2011-09-07
5
410 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:peterkiers
5 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 36495155
Are you appending the text to the existing text or overwriting the text with new text ?

You can test simply by using the arrow keys when the cursor is in the text box.
ps.  You might need to have the textbox property - multiline - set to true.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36495161
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36495187
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
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36495216
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.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36495254
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question