Solved

How to autosize a textbox?

Posted on 2011-09-07
5
407 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now