Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Can radio button controls be resizable?

Is there any way to get a radio button control to have more or fewer entries by varying its properties? Or is always the size it is when it's first created?

Basically, I'm creating a form which may allow the user to select up to 5 choices. I prefer buttons to e.g. an edit list because the control is oriented horizontally and I'd like the choices to read left to right.

Comments

  • Just to be clear, by "resizable" do you mean the number of radio buttons or the overall horizontal width of the radio group?
  • I should have specified. Yes, the number of radio buttons. The form is called by another subroutine and one of the subroutine's inputs is the choices available in a comma-delimited list. There won't be more than 5 choices. I'd like to be able to create a 2, 3, 4, 5 choice radio button with the text that's coming in. In another form I have a similar issue, but there, the orientation is vertical - so I just use a single column edit list.
  • I did something similar for a different reason. I was after vertical radio buttons but with greater spacing between them. The goal was different but you could probably use the same approach.
    In this there are four choices only but the radio button control has seven options. Upon the create of the window the even numbered options are made invisible.

    I suspect you could do the same with your horizontal radio buttons. Create it in the form designer with all five options but upon create, hide the options that aren't applicable.

    To refer to the individual options you use ctrlname.value
    Eg: set_property(@Window:".RB_PERIOD.NULL", "VISIBLE", false$)
  • I was trying that, but it seemed that it would only turn off the entire control, or do nothing. The examples in the documentation are a bit sparse.

    In your code, how are you telling it which options to turn off?
  • Eg: set_property(@Window:".RB_PERIOD.NULL", "VISIBLE", false$)

    The control name is "RB_PERIOD" so set_property(@Window:".RB_PERIOD", "VISIBLE", false$) will hide the entire control but if you concatenate the, (and this is where I'm a bit sketchy because I can't remember), individual label or value to the control name, you are then referring to that option only.

    In my example I've concatenated "NULL" to the control name because I've labelled it "Null" but the value is also "Null" so I'm not sure which one OI is looking at.
  • Just tested it and confirmed it is the label.
    So to refer to the individual option you use windowName.CtrlName.Label, all in uppercase
  • @alvarofernandez - In case this helps, what @AusMarkB is doing is working with the properties of the individual radio buttons within the radio group control. As he noted, you have to append the label to the the radio group control to identify a specific button. Then you can do other things such as making them invisible and/or changing the x/y position to spread out the individual buttons.
  • edited October 2021
    changing the x/y position

    Damn, that would have been better.
  • edited October 2021
    Thanks all. I'll test it later today.

    To your point Don, I've been moving the radio button around already :-) - I shrink the form and expand it based on the number of rows and columns displayed, then determine where to place the radio button control if the option string is present, or I place an edit line there instead.

    The radio control overall is OPTIONS, but the individual labels are still called RADIO_1, RADIO_2, etc. So I currently turn them all off, then turn some on based on how many options there are, e.g.:

    SET_PROPERTY("OPTIONS.RADIO_1","VISIBLE",TRUE$)
    SET_PROPERTY("OPTIONS.RADIO_1","TEXT","Commit")
    SET_PROPERTY("OPTIONS.RADIO_2","VISIBLE",TRUE$)
    SET_PROPERTY("OPTIONS.RADIO_2","TEXT","Place")
    SET_PROPERTY("OPTIONS.RADIO_3","VISIBLE",FALSE$)

    Now I can hammer at this, knowing that in principle it is possible to make a specific radio button control to turn on or off.
  • I didn't know you could do this. This is very useful

    thanks
  • Well, it's almost working. All other bugs in the form seem to have been resolved, and the radio button is turned on and off properly depending on the situation. However, the radio button text stubbornly refuses to change.

    I do GOSUB DO_BUTTONS

    DO_BUTTONS: * CURRENTLY UP TO 5 BUTTONS /* To refer To individual options IN radio button, windowName.CtrlName.Label */ Set_Property(OPTIONS,"VISIBLE",TRUE$) FOR I = 1 To 5 I_BUTTON = OPTIONS:".RADIO_":I OT = Field(OPTION_STRING,",",I) IF Len(OT) Then OT1 = OT[1,MAX_BUTTON_STRING_LENGTH$] Set_Property(I_BUTTON,"VALUE",OT1) Set_Property(I_BUTTON,"VISIBLE",TRUE$) End ELSE Set_Property(I_BUTTON,"VISIBLE",FALSE$) End NEXT I

    But the control does not change its text.. I can verify that the labels are all radio_1, radio_2, etc.

  • You don't appear to be changing the TEXT property. The VALUE property is the value returned to the program, the TEXT property is what the user sees
  • and in testing this I found something I hadn't considered.
    Whilst you can change the text, the new text will only occupy the same space as the original text so if your new text is longer than the original, it will end up truncated.

  • Whilst you can change the text, the new text will only occupy the same space as the original text so if your new text is longer than the original, it will end up truncated.

    Which is why you might need to programmatically increase the width of the radio group control.
  • edited October 2021

    This is where I'm stuck right now. I have modified the code to look like this:

    FOR I = 1 To 5 I_BUTTON = OPTIONS:".RADIO_":I OT = Field(OPTION_STRING,",",I) IF Len(OT) Then OT1 = OT[1,MAX_BUTTON_STRING_LENGTH$] Set_Property(I_BUTTON,"TEXT",OT1) Set_Property(I_BUTTON,"VALUE",I) Set_Property(I_BUTTON,"VISIBLE",TRUE$) End ELSE Set_Property(I_BUTTON,"VISIBLE",FALSE$) End NEXT I
    As you see, I'm modifying both the label shown as well as what is returned. Basically, I want to return a simple integer count 1, 2, etc. when the user selects the 1st, 2nd, etc. item in the radio button. However, the control refuses to change at all and stays stuck as displayed. It's confusing. Am I creating the right access string?
  • The labels in your screenshot are "OPTIONS_1", "OPTIONS_2" etc so to speak to the first option, I_Button should be something like
    "MYWINDOWNAME.MYCTRLNAME.OPTIONS_1"

    It's a little difficult to tell what it actually is based on your example.
    What is the value of "OPTIONS" in your I_BUTTON assignment? It looks like OPTIONS may be your complete control name, which is fine but they you're referring to ".RADIO_":I instead of ".OPTIONS_":I.

    As for setting the "VALUE" property, there's no need for that. Just assign it 1,2,3,4,5 in the form designer and retrieve the "VALUE" of the control itself.

    Try this

    Options = @Window:".OPTIONSRADIO" FOR I = 1 To 5 I_BUTTON = OPTIONS:".OPTIONS_":I OT = Field(OPTION_STRING,",",I) IF Len(OT) Then OT1 = OT[1,MAX_BUTTON_STRING_LENGTH$] Set_Property(I_BUTTON,"TEXT",OT1) // Set_Property(I_BUTTON,"VALUE",I) Set_Property(I_BUTTON,"VISIBLE",TRUE$) End ELSE Set_Property(I_BUTTON,"VISIBLE",FALSE$) End NEXT I
Sign In or Register to comment.