Abdu Abdul

Abdu Abdul

  • 1.3k
  • 409
  • 15.4k

Adjust the height of labels location and autosize to content help out!

Nov 13 2021 10:35 PM

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 is always fixed. the don't base on the content scalability. I want I such a away that the moment label1 scale to fit parent container, so does the label2 to shift up base on the label1 bottom not stay fixed. A tried un-anchoring  them but no result.

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


Answers (2)