c# - Autoresize textbox control vertically -


in c# form, have panel anchored sides, , inside, textbox, anchored top/left/right.

when text gets loaded textbox, want auto expand vertically don't need scroll textbox (scroll panel @ most, if there more text doesn't fit panel). there way textbox? (i'm not constrained use control if there's control fits description, feel free mention it)

i'll assume multi-line text box , you'll allow grow vertically. code worked well:

    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;     } 

you ought reasonable when text box empty, setting minimumsize property.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -