# VBForums CodeBank > CodeBank - ASP / ASP.NET / MVC / Web API >  Auto setting a textbox height property to fit text.

## peteshir

This is an FYI Only.

I spent a lot of time trying to get a asp textbox, that has it's multiline property set to true, to automatically set it's height property
It always seems to come up with a default value of 120px no matter how big the text inside the box is.

Anyway, to solve the problem I created a function as follows in a module;

    Public Function SetTextHeight(n As Int32) As Int16
        'n is the length of the string in the textbox
        Return n \ 70 + 1
    End Function

Now I set the width of the Textbox to a width of 70 columns. The 70 matches the 70 in the function.
if you set the column width to 50, change the 70 in the function to 50. Could also be sent as an argument.
Now I use the return value as the Rows property of the textbox. see the following snippet.

            txt = New TextBox
             txt.ReadOnly = True
            txt.Font.Size = "16"
            txt.Font.Bold = True
            txt.ForeColor = Drawing.Color.DarkGreen
            txt.BackColor = Drawing.Color.Moccasin
            txt.Columns = 70 'This is where the column width is set.
            txt.Wrap = True
            txt.TextMode = TextBoxMode.MultiLine
            txt.Text = r.Item("Message")
            txt.Rows = SetTextHeight(Len(txt.Text))
            pnlMess.Controls.Add(txt)



Very simple and it seems to work rather nicely.

----------


## Joacim Andersson

_Thread moved to the CodeBank - ASP.Net forum._

----------

