Set the
TextMode
property of the
TextBox
to
MultiLine
and adjust the
width
and
height
accordingly.
I hope this helps you well.
[EDITED]
Ok. I gave you a prototype that will help you to finish up by yourself.But there are certain factors that you should consider. Such as
1.The type of
font size
,
font family
..., used in the
textbox
.
2.Is it
underlined
?
3.When calculating the
width
or
height
, try not to break the word, and many more factors.
Prototype.
public static class ResizeExtension
{
public static void Resize(this TextBox textBox, int resizeFactor = 8, int maxCharacterPerLine = 20)
{
string textValue = textBox.Text;
if (string.IsNullOrEmpty(textValue))
return;
int width = textValue.Length * resizeFactor;
int calculateHeight = textValue.Length % maxCharacterPerLine;
int height = Convert.ToInt32(textBox.Height.Value) * (calculateHeight > 0 ? calculateHeight : 1);
textBox.Width = Unit.Pixel(width);
textBox.Height = Unit.Pixel(height);
}
}
How to use it? Just call this method in your
TextBox
instance.E.g if your WebForm contain
textbox1
instance then call the
Resize
method.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
textBox1.Resize();
}
I hope this helps you well.