Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
How to auto resize a textbox in C#?
Posted
Updated 15-Oct-10 2:44am
v2
Comments
aayu 15-Oct-10 8:44am    
r u talking about web aur window
if web then sandeep answer is correct.

Your question is too short to get your actual scenario.
Does this help: Resize a TextBox on a Form [^]
 
Share this answer
 
private void textBox1_TextChanged(object sender, EventArgs e) {
        Size sz = new Size(textBox1.ClientSize.Width, int.MaxValue);
        TextFormatFlags flags = TextFormatFlags.WordBreak;
        int padding = 3;
        int borders = textBox1.Height - textBox1.ClientSize.Height;
        sz = TextRenderer.MeasureText(textBox1.Text, textBox1.Font, sz, flags);
        int h = sz.Height + borders + padding;
        if (textBox1.Top + h > this.ClientSize.Height - 10) {
            h = this.ClientSize.Height - 10 - textBox1.Top;
        }
        textBox1.Height = h;
    }



do vote if answer is helpful
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900