Resize text in a label based on window size

Maybe I’m missing something…

Is there a simple way to resize the text in a label as a window containing the label is resized? I’m making a simple count up timer that displays MM:SS in a label and that text needs to be resizable based on monitor size.

Compute it, not a complex task (excepted if you accept 800 x 600 or 640 x 480 monitor sizes and a large window).

use the locking mechanism in the IDE to lock all sides of the labels
thus if you grow the window, then the label will grow too.
Capture d’écran 2023-12-01 à 14.36.51

I locked all sides and the label enlarges but not the text.

Screen Shot 2023-12-01 at 8.57.47 AM

you must add the “resize” event to the label
and calculate (and change) the font size from the height of the label

And also check the width so that you do not overflow the width in case the user makes the window taller but not wider. The graphics object .TextWidth is useful here.

There appears to be no resize event for labels. The following in the window resize event appears to work:

lbTime.FontSize = lbTime.Width/3

Thanks!

You may want to see what happens if you drag the window wider but not taller. Users do some weird stuff. And then check both the window width and height to make sure font fits.

1 Like