Adjust the height of labels location and autosize to content

Manchi 21 Reputation points
2021-11-19T13:48:17.683+00:00

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());  
            label10.Height = int.Parse(Math.Round(size.Height + 2, 0).ToString());  
  
            label10.Location = new Point(label1.Left, label1.Bottom);  
  
            label9.Location = new Point(label10.Left, label10.Bottom);  
            this.Height = label9.Bottom + 80;  

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
151023-screenshot-a.png

150918-screenshot-b.png

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,919 questions
{count} votes