I have a CheckBoxGadget and a button. What I would like to be able to do is this,…
If the CheckBox is not checked, the button state is disabled. If the user checks the CheckBox, the button state is immediately enabled. If the CheckBox is enabled and the user unchecks the CheckBox, the button is immediately disabled. To do this, the CheckBox state would have to be constantly monitored for any changes. How can I accomplish this?
Enable/disable button with checkboxgadget
Enable/disable button with checkboxgadget
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
Re: Enable/disable button with checkboxgadget
Perhaps something like this:
Code: Select all
Enumeration window
#w_Main
EndEnumeration
Enumeration gadget
#g_CheckBox_chk
#g_Button_btn
EndEnumeration
Procedure buttonEvents()
Protected c = Random(200, 60)
SetWindowColor(#w_Main, RGB(c + 1, c, c - 1))
EndProcedure
Procedure checkBoxEvents()
Protected state = GetGadgetState(#g_CheckBox_chk)
Protected output.s = "checkbox state: "
If state = #PB_Checkbox_Checked
output + "Checked"
SetGadgetText(#g_Button_btn, "Push Me")
DisableGadget(#g_Button_btn, #False)
ElseIf state = #PB_Checkbox_Unchecked
output + "Unchecked"
SetGadgetText(#g_Button_btn, "Disabled")
DisableGadget(#g_Button_btn, #True)
EndIf
Debug output
EndProcedure
OpenWindow(#w_Main, 0, 0, 300, 100, "Checkbox Test", #PB_Window_SystemMenu)
CheckBoxGadget(#g_CheckBox_chk, 30, 10, 80, 20, "Click Me")
ButtonGadget(#g_Button_btn, 120, 10, 120, 20, "Disabled")
DisableGadget(#g_Button_btn, #True)
BindGadgetEvent(#g_CheckBox_chk, @checkBoxEvents())
BindGadgetEvent(#g_Button_btn, @buttonEvents())
Repeat
Repeat
event = WaitWindowEvent()
If event = #PB_Event_CloseWindow
quit = #True
EndIf
Until event = 0 Or quit = #True
Until quit = #True
Re: Enable/disable button with checkboxgadget
Thank you very much. Much appreciated!
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
Re: Enable/disable button with checkboxgadget
Worked perfectly! Thank you so much.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
Re: Enable/disable button with checkboxgadget
This is how I'd do it (if you don't want to bind gadgets):
Code: Select all
OpenWindow(0, 200, 200, 300, 50, "Checkbox Test", #PB_Window_SystemMenu)
CheckBoxGadget(0, 30, 10, 80, 20, "Click Me")
ButtonGadget(1, 120, 10, 120, 20, "Disabled")
DisableGadget(1, #True)
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
If EventGadget() = 0 ; Checkbox clicked.
DisableGadget(1, 1 - GetGadgetState(0))
EndIf
EndIf
Until event = #PB_Event_CloseWindow