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
Hi Boris,
I had a similar question and I was lucky for your answer. However, my questions goes a little bit deeper. Your solution is a good approach for single line content, but the cell content in my grid (which I assume has the same handling than an UltraLabel) can be multi lined (word wrap).
My need is now: Reduce the font size in a way that the whole text is readable while the cell size keeps stable. How do I handle this?
Thanks.
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)); } }
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.