Reputation: 97
i made usercontrol with two textboxses. one of them is multiline and other textbox is single line which stays at bottom of multiline textbox. i want to change multiline textbox's height based on number of lines of content and stick single line textbox to this multiline textbox visually(no spacing between two textboxes).
Upvotes: 0
Views: 897
Reputation: 54453
Is this what you are looking for?
SizeF size;
private void textBox1_TextChanged(object sender, EventArgs e)
{
using (Graphics G = textBox1.CreateGraphics())
size = G.MeasureString("Xy_", textBox1.Font, 999);
textBox1.Height = (int)(textBox1.Lines.Count() * size.Height + 5);
textBox2.Top = textBox1.Bottom - 1;
}
The using line really could and should be moved to the Form constructor.. Depending on your font and Borders you want to adapt the two correction numbers..
Upvotes: 1