Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

c# - Auto Scale text to fit the screen in mono

I'm trying to scale a given text, e.g "123 V.1-4", to fit the screen in mono. I tried increasing the font size till the screen is not bigger.

My main problem is that I cannot retrieve the size of the label with a new font quickly? (I'm retrieving with label.GetSizeRequest(out width, out height);)

So any solutions on how to scale the font/text?

Thanks

question from:https://stackoverflow.com/questions/65617413/auto-scale-text-to-fit-the-screen-in-mono

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When the label is resized as you change the font size, the SizeRequest and SizeAllocated events will fire. What you could do is set the font size, then in the SizeAllocated event for the label, set the font size again. You will clearly have to stop the loop at some point, I assume you would cease increasing the font size when your label dimensions outstrip those of the window or screen etc.

However, have you considering using Pango and a drawing area instead?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...