Click here to Skip to main content
12,075,542 members (50,126 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C#
How to auto resize a textbox in C#?
Posted 15-Oct-10 3:35am
Edited 15-Oct-10 3:44am
Johnny J.139.5K
Aarti2010 15-Oct-10 8:44am
r u talking about web aur window
if web then sandeep answer is correct.
Rate this: bad
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 [^]
Rate this: bad
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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 15 Oct 2010
Copyright © CodeProject, 1999-2016
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