Adjust the height of labels location and autosize to content

Adjust the height of labels location and autosize to content

I created 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 doesn't change at all.

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;

Image Samples

https://preview.redd.it/5xjhpokigmz71.png?width=316&format=png&auto=webp&s=a7ead9bb874189e6ab6fc58086912de86305fec5https://preview.redd.it/p92ykm6lgmz71.png?width=527&format=png&auto=webp&s=d5241fbff8979a9f71f2524c038ddd57f070c714

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

0 Answers
Ask question now
Never leave your website again in search of code snippets by installing our chrome extension.