Autoadjust textbox control .NEt C#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Aug 17, 2012, 2:02 AM EDT
try this 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; }Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 17, 2012, 2:05 AM EDT
Anchor more preferred.
Check this correct answer if it helped