Sign in to follow this  
Followers 0
qwert

Alternative to Tiny Radio Buttons

3 posts in this topic

I’ve always wanted an alternative to the tiny radio buttons that Windows insists on using. The fact that they don’t react to size settings is a glaring shortcoming of Windows— one that’s been around since monitor sizes went beyond 640x480 (20 years?). Equally bad, radio buttons don’t conform to $GUI_BKCOLOR_TRANSPARENT like other controls do, so they’re difficult to use on patterned backgrounds.

 

After trying a couple of the GDI+ approaches, I experimented with some of the simple style options. To my surprise, $BS_PUSHLIKE gave a result that is sizable and that preserves the radio button group behavior* (important because the states can easily be read by the script). To my greater surprise—and actually the result of a coding mistake—I found that you can write text onto the resulting buttons.

 

They don’t have the circle appearance, of course. But a user will likely overlook that difference in order to have something they can easily see. Plus, larger sizes give a target area that’s much easier to click on. And to make the current selection perfectly clear, I added a pointer character on the selected button. (Other characters are tricky to use.)

 

Here’s what they look like in Win7:

post-29172-0-12324900-1411999841_thumb.p

 

I’ll continue to experiment with these for different uses and will certainly appreciate any feedback.  Here's the code for the above example:

;   Simple alternative to tiny radio buttons
;   ... by qwert, september, 2014
;
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

$hGUI = GUICreate("Alternative Radio Buttons", 700, 300, -1, -1)
GUISetBkColor(0xCCDDEE)
GUISetFont(12, 400, 0, "Arial")
;;;DllCall("UxTheme.dll", "none", "SetThemeAppProperties", "int", 0)    ; <<<<<<<<< THIS DOES WORK TO TURN OFF THEME

GUICtrlCreateGroup("Windows Radio Buttons", 40, 40, 260, 184)
$choiceA = GUICtrlCreateCheckbox("", 100, 90, 13, 14, $BS_AUTORADIOBUTTON)  ;<<<<< can't control checkbox size in Windows
GUICtrlCreateLabel("Choice A", 124, 88, 100, 20)
$choiceB = GUICtrlCreateCheckbox("", 100, 120, 13, 14, $BS_AUTORADIOBUTTON) ;<<<<< can't control checkbox size in Windows
GUICtrlCreateLabel("Choice B", 124, 118, 100, 20)
$choiceC = GUICtrlCreateCheckbox("", 100, 150, 13, 14, $BS_AUTORADIOBUTTON) ;<<<<< can't control checkbox size in Windows
GUICtrlCreateLabel("Choice C", 124, 148, 100, 20)
GUICtrlSetState ($choiceB, $GUI_CHECKED)
GUISetState(@SW_SHOW)

GUICtrlCreateGroup("Alternative Radio Buttons", 340, 40, 260, 184)
$choice1 = GUICtrlCreateCheckbox("", 400, 88, 20, 20, BitOR($BS_AUTORADIOBUTTON, $BS_PUSHLIKE))  ; size can be anything
GUICtrlCreateLabel("Choice 1", 432, 89, 100, 20)
$choice2 = GUICtrlCreateCheckbox("", 400, 118, 20, 20, BitOR($BS_AUTORADIOBUTTON, $BS_PUSHLIKE))
GUICtrlCreateLabel("Choice 2", 432, 119, 100, 20)
$choice3 = GUICtrlCreateCheckbox("", 400, 148, 20, 20, BitOR($BS_AUTORADIOBUTTON, $BS_PUSHLIKE))
GUICtrlCreateLabel("Choice 3", 432, 149, 100, 20)

$symbol = ChrW(9658)    ; Unicode for pointer in Arial
;$symbol = ChrW(9642)   ; Unicode for small square in Arial
;$symbol = ChrW(9679)   ; Unicode for small circle in Arial
GUICtrlSetState ($choice1, $GUI_CHECKED)                ; set initial selection
GUICtrlSetData($choice1, $symbol)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
   Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $choice1
        GUICtrlSetData($choice1, $symbol)
        GUICtrlSetData($choice2, "")
        GUICtrlSetData($choice3, "")
    Case $choice2
        GUICtrlSetData($choice1, "")
        GUICtrlSetData($choice2, $symbol)
        GUICtrlSetData($choice3, "")
    Case $choice3
        GUICtrlSetData($choice1, "")
        GUICtrlSetData($choice2, "")
        GUICtrlSetData($choice3, $symbol)
   EndSwitch
sleep(10)
WEnd

 

* I realize that the visual effect is entirely dependent of the current theme and that some themes might give lesser results. For example, enabling the default theme (see line in code) gives a fairly poor effect.

 

 

 

Share this post


Link to post
Share on other sites



Good idea !

But the number of characters that appear "correctly" is limited...

With Segoe UI Symbol font, you can also try with ChrW ( 10173 )  :)

1 person likes this

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

But the number of characters that appear "correctly" is limited...

.

So true.

But I just learned that other style parameters—plus font size—help make it easier to adapt characters for use.  Here's an example using the box character:

post-29172-0-35921000-1412005092_thumb.p

Required code:

$symbol = ChrW(9642)    ; Unicode for small square in Arial
:
$choice1 = GUICtrlCreateCheckbox("", 400, 88, 20, 20, BitOR($BS_AUTORADIOBUTTON, $BS_PUSHLIKE, $BS_CENTER, $BS_VCENTER))  
GUICtrlSetFont(-1, 24, 400, 0, "Arial")
:

.

Of the ones I've tried, I think this gives the best overall effect.  But suggestions are welcome, of course.

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0