Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
175
Ultralabel and autosize
posted

This is what I am trying to accomplish...

 I want the ultralable to autosize width up to a maximum, and i want it to autosize height and wrap text.

 So I have

myLabel.WrapText=true;

myLabel.AutoSize = true;

myLabel.MaximumSize = (200,0);

 This does not work. It only expands the width up to the specified maximum. The label will not grow as necessary in height to display the text. Is there some other way to accomplish this or am I missing something?

Parents
  • 469350
    Verified Answer
    Offline posted

    I'm not sure I see how this would work. AutoSizing the label involves measuring the text. In order to do that, either the width or the height has to be fixed. If both are variable, then there are any number of potential ways that the text would be displayed. You could have 5 words on a single line or 1 words on each of 5 lines.

    There's no way to measure text in Windows that I know that allows you to specify a Maximum width - only a specific width. So in order for any control to accomplish what you want here, the control would had to measure the text with a width of 200. If the text wrapped at this point, that would be fine and it could determine the appropriate height. But if it was less, then it would basically have to measure the text over and over again with decreasing widths to find the point where it stopped wrapping. That would be pretty inefficient - although I guess it wouldn't be so bad since it only happens when the text changes. 

    Now, if you want to set the width of the label to 200 and only autosize the height, that would be possible. What you would do is derive a class from the UltraLabel and override the AutoResizeHeightOnly property and return true. 

Reply Children