Abdu Abdul

Abdu Abdul

  • 1.3k
  • 409
  • 14.8k

Adjust Labels to auto adjust top anchor and bottom anchor

Nov 11 2021 11:04 PM

I have a user a control that i call on another form. everything is working fine and amazingly good. but there is one problem that serve as an obstacle to me. i have Label1, Label2 on the user control, they both adjust their heigt at run time. but the problem is they dont scale, they always stayed at a fixed position despite height changing. 

 

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.Top = label1.Bottom;

this.Height = label2.Bottom + 34;


Attachment: sample.zip

Answers (4)