2
votes

enter image description here

Like the image above, I want to make a certain Label with fixed width without any scrollbar. It means, actually, the width of Label is changed with the size of outer Panel, however, the height of the Label is just fit to display the whole text inside.

If I set the AutoSize property to True, I can't set the width of the Label.

Thank you!


The important thing is the '...XYZ' part that the HEIGHT of the Label is just fit to the end of the text. No more space or no less space.

I want to make the height of the Label to be just fit to the text inside. The width is changing to fit the width of Form size, which is intended, while the height of the Label is constant, which is NOT.

3
Check Anchor propertySteve

3 Answers

1
votes

I did a trick for the solution. (or maybe this is an ordinary solution)

I set the AutoSize property to true then wrapped the Label within a FlowLayoutPanel.

I anchored the Flowable Panel TOP,LEFT and RIGHT as well as set the AutoSize to true.

0
votes

You need to set 'Autosize' to false and then use the 'Anchor' property to pin the right side of the label (as well as the left and top which are already pinned by default).

0
votes

The Anchor property from MSDN

Use the Anchor property to define how a control is automatically resized as its parent control is resized. Anchoring a control to its parent control ensures that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resized.

As you explain that this label is inside a panel, then you need to set the Anchor property also for the Panel inside the Form (the object that actually resizes itself). You could also look at the similar Dock property