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.107K
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 483
1 Maciej Los 360
2 OriginalGriff 308
3 Yogesh Kumar Tyagi 275
4 CHill60 220
0 OriginalGriff 6,367
1 Sergey Alexandrovich Kryukov 5,296
2 Maciej Los 3,384
3 Peter Leow 3,259
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web03 | 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