Resize Textbox to show all text

Posted on 2009-02-17
Last Modified: 2012-05-06
I currently have a textbox which is populated from the database, I was wondering how I would go about resizing the textbox to fit this text. Now I've seen it done like:

Dim mySize As  New System.Drawing.SizeF

Dim myFont As New System.Drawing.Font  (Me.TextBox1.Font.FontFamily, Me.TextBox1.Font.Size)

mySize = e.Graphics.MeasureString("This is a test", myFont)

Me.TextBox1.Width = CType(Math.Round(mySize.Width, 0), Integer)

Open in new window

Question by:directxBOB
    LVL 12

    Accepted Solution

    Me.TextBox1.Width = Unit.Pixel(8 * TextBox1.Text.Length)
    LVL 3

    Assisted Solution

    Try jquery and auto grow plug-in. Please check followin link. Cool coding.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now