I have a windows form with a multiline textbox control on it, the same size as the form. What I want is for textbox to expand downwards as the user types In more text to fill it. To do that I have the following code in TextChanged event:
private void textBox1_TextChanged(object sender, EventArgs e)
const int padding = 3;
//get number of lines (first line is 0)
int numLines = this.textBox1.GetLineFromCharIndex(this.textBox1.TextLength) + 1;
//get border thickness
int border = this.textBox1.Height - this.textBox1.ClientSize.Height;
//set height (height of one line * number of lines + spacing)
this.textBox1.Height = this.textBox1.Font.Height * numLines + padding + border;
I aslo set Form's property AutoSize to true but the form only grows with the textbox automatically if textbox is not docked to fill the form. And I do need to dock my textbox.
Why isn't my form growing when the textbox is docked and what can I do to fix that?