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
75
Can we shrink fit text in UltraLabel?
posted

I am displaying text using UltraLabel. However, this text length keeps varying and at times the length of the assigned text exceeds the label space. As a result the text is cut and the entire string is not visible.

Any ideas how I can resolve this issue? What I am looking for is a way to shrink the text to fit to the label size.

 

Thanks

Rahul

Parents
No Data
Reply
  • 71886
    Suggested Answer
    Offline posted

     

    Hello rahulgathoo,

     

    From what I have understood, you want your string to fit in some way in the ultraLabel control without changing the label's sizes at all and all of the text to be visible.

    One possible approach is the following:

     

      

    float baseSize;

     

            private void ultraLabel1_TextChanged(object sender, EventArgs e)

            {

                baseSize = ultraLabel1.Font.SizeInPoints;

                if (ultraLabel1.Text.Length * ultraLabel1.Font.SizeInPoints > ultraLabel1.Size.Width)

                {

                    ultraLabel1.Font = new Font("Microsoft Sans Serif", (baseSize * 0.7f));

                }

            }

     

    Whenever your text in the label changes, if it exceedes the length of the control, it will make its font size smaller.

    That's just an example - you can try changing the float number or the font family to whatever fits you.

    I think this solves your issue.

     

    Please feel free to ask anything you want to know about this scenario and let me know if I have misunderstood it.

    I hope I have pleased your needs.

     

Children