Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
How to auto resize a textbox in C#?
Posted 15-Oct-10 2:35am
Edited 15-Oct-10 2:44am
Johnny J.108.1K
v2
Comments
Aarti2010 at 15-Oct-10 8:44am
   
r u talking about web aur window
if web then sandeep answer is correct.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your question is too short to get your actual scenario.
Does this help: Resize a TextBox on a Form [^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 434
1 Nirav Prabtani 338
2 Abhinav S 170
3 PIEBALDconsult 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 15 Oct 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100