Method resize RadioButton/Checkboxes


I have a method that I use to resize my labels automatically depending on the text inside (localized constant). It’s using a graphics and writing a text and returning g.TextWidth(string)

I wanted to do the same things for the radio buttons/check boxes but I do not know how to get the size of the circle of the radio button or square of the checkbox and the space between the caption and the square/circle.

Do anyone have a hint regarding that?

The method is for windows and macOS (I do not know if there are differences in size between the systems regarding that)

Thank you,


No, but maybe FlowLayout by Einhugur can help with that? :slight_smile:

Thank you,

it should work but I would have liked to have something that send me back the width instead of placing the controls automatically

RadioButton is fairly simply, the circle is always the same size (on macOS at least). It’s almost impossible with RadioGroup, as there seems to be no rhyme or reason to the spacing (at least that I’ve been able to work out).

For MacOS, an API exists to automatically adjust the size of a given control (you pass the handle of the control to the API); the MBS plugin has the equivalent, IIRC.
I don’t remember the exact API name though. It’s something like “SetControlBestSize”.

NSControl has a method called “sizeToFit”, it will shrink the width down to fit the contents. It works for simple controls like Labels, however, if there are multiple “cells” within the control it will crash the application. This means it doesn’t work for DesktopRadioGroups.

It will work with DesktopRadioButton, DesktopCheckbox.

The declare would be:

Declare Function sizeToFit lib "AppKit" selector "sizeToFit" (NSControlInstance as Ptr)

' Call it like this:
sizeToFit( MyControl.Handle )
1 Like

Thank you,

there is nothing like that for windows ?

It’s a very long time since I’ve played with the Windows API. Put it this way, it was Win32 (and yes, 32bit) :slight_smile:

I tend to think Windows has less “convenient” APIs than Mac OS.

Note: If you watch my constraints webinar from Thursday, there’s a few slides about Intrinsic Content Size. The controls that have an intrinsic size are the ones that support SizeToFit. Otherwise, the reason your app crashes is because the item that you’re sending that command to doesn’t have a way to measure itself.

Excellent, will take a watch.

Very interesting webinar and well worth a look. The one thing not demonstrated in the Webinar was the RTL language support it brings (for Arabic, Hebrew and others). In short if you ever want to support RTL languages, always use Leading and Trailing and never Left and Right (for reversible parts of the interface).

Such a shame about the DesktopRadioGroups though.

For others, If you haven’t seen it you can access it via this page: