Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Win32::GUI RadioButton

by petecm99 (Pilgrim)
on Jan 25, 2011 at 20:50 UTC ( [id://884217]=perlquestion: print w/replies, xml ) Need Help??

petecm99 has asked for the wisdom of the Perl Monks concerning the following question:

Good day Monks,

I've seen my question on a few different forums, and no one has offered a response, so I'll try it here...

I just added a couple of Radio Buttons to my Win32::GUI program, and noticed that it is not intuitively obvious how they tie together (i.e. select one button, and the other(s) become unselected).

Does anyone know the property that ties them together to make the radio buttons a part of a set? I fear that I will only be able to have one set of radio buttons per form.

Here is some code for two buttons that are a matched pair, even though nothing in the properties declare that they should be...

my $RB_Prod = $W1->AddRadioButton( -text => "Production", -name => "RB_PROD", -pos => [ 100, 10 + 30*($PgmCtr-1)], -width => 90, -height => 20, -foreground => 0xFFFFFF, -background => 0xFF7F7F, ); my $RB_Test = $W1->AddRadioButton( -text => "Test", -name => "RB_TEST", -pos => [ 200, 10 + 30*($PgmCtr-1)], -width => 60, -height => 20, -foreground => 0xFFFFFF, -background => 0xFF7F7F, );
Thanks for your wisdom...

Pete

Replies are listed 'Best First'.
Re: Win32::GUI RadioButton
by BrowserUk (Patriarch) on Jan 25, 2011 at 21:06 UTC

    The attribute you are looking for is WS_GROUP. You set this on the first button (in tab-order) of the set of buttons that you want to be linked together and omit it on the rest. The group is 'closed' the next time a button is created with the WS_GROUP flag set.

    See Using Radio Buttons for more info.

    Note:I don't know how you actually specify this using Win32::GUI. You might find Win32::GUI Window Styles and Transparency useful.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Win32::GUI RadioButton
by kejohm (Hermit) on Jan 26, 2011 at 00:12 UTC

    You can use the -group option when creating the control. As mentioned by BrowserUk above, you specify it on the first control you want in the group and all controls created after are in the same group until you create another control with the -group option. Here is an example:

    #!perl use strict; use warnings; use feature qw(:5.12); use Win32::GUI qw(); use Win32::GUI::Constants qw(CW_USEDEFAULT); my $winMain = Win32::GUI::Window->new( -name => 'winMain', -text => 'Radio Buttons', -size => [320,240], -left => CW_USEDEFAULT, ); # These radio buttons are in one group my $rad1 = $winMain->AddRadioButton( -name => 'rad1', -text => 'rad1', -pos => [10,10], -group => 1, ); my $rad2 = $winMain->AddRadioButton( -name => 'rad2', -text => 'rad2', -pos => [10,30], ); # These radio buttons are in another group my $rad3 = $winMain->AddRadioButton( -name => 'rad3', -text => 'rad3', -pos => [10,50], -group => 1, ); my $rad4 = $winMain->AddRadioButton( -name => 'rad4', -text => 'rad4', -pos => [10,70], ); $winMain->Show(); Win32::GUI::Dialog();
      Thanks, worked like a charm!
Re: Win32::GUI RadioButton
by Anonymous Monk on Jan 25, 2011 at 21:19 UTC
    I believe having the same parent makes them related

      Not so. It is not only possible, but normal to have multiple groups with the same parent.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://884217]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2025-12-09 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (88 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.