Search code snippets, questions, articles...

Adjust the height of labels location and autosize to content

I create a user control. i have label (labe1, label2, label3). this labels have auto size property to false, and the user control scale base on the combine height of the three labels. my problem is the height of the labels work fine but their location
Graphics g = CreateGraphics();

SizeF size = g.MeasureString(label1.Text, label1.Font, label1.Width);

label1.Height = int.Parse(Math.Round(size.Height + 2, 0).ToString());

label2.Height = int.Parse(Math.Round(size.Height + 2, 0).ToString());

label2.Location = new Point(label1.Left, label1.Bottom);

label2.Location = new Point(label2.Left, label2.Bottom);

this.Height = label9.Bottom + 35;

I usually get unnecessary space between label1, label2 and label3 after resizing, their location still remain stuck instead of adjusting to go up. the anchor property doesn't seem to work

Search Index Data (The code snippet can also be found with below search text)

Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet