How can I automatically increase/decrease TextBox and Windows Form size according to text Length?
You can try overriding the OnTextChanged event, then changing the Width depending on the size of the text.
protected override OnTextChanged(EventArgs e)
{
using (Graphics g = CreateGraphics())
{
SizeF size = g.MeasureString(Text, Font);
Width = (int)Math.Ceiling(size.Width);
}
base.OnTextChanged(e);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With