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
875
Autosize UltraLabel height
posted

If I set AutoSize = true on an UltraLabel, its height becomes fixed and its width expands/collapses to accommodate its text.

What I can't figure out is how to fix its width and have the UltraLabel autosize its height to accommodate the height of the wrapped text.

We're migrating from a set of custom controls where we had FixedWidthVariableHeight and FixedHeightVariableWidth layout options. I really need to find a way of achieving FixedWidthVariableHeight.

Please don't tell me I have to roll this myself and measure text. :)

Thanks for your help!
Jim Honeycutt

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Jim,

    The control doesn't natively support this.But there is a kind of sneaky way you can do it.

    What you do is derive a control from UltraLabel and override the constructor and set AutoSizeHeightOnly to true.

        class UltraLabelWithAutoHeight : UltraLabel
        {
            public UltraLabelWithAutoHeight()
                : base()
            {
                this.AutoSizeHeightOnly = true;
            }
        }

    Note that the designer will not let you change the Width of the control once AutoSize is set to true. So this is a little inconvenientto work with at design-time. But it's easier than measuring the text yourself. 

Reply Children