To use the button the file "OnOffButton.pbi" first needs to be copied to your project folder ready for inclusion in your project.
Then add the line:-
IncludeFile "OnOffButton.pbi"
at the start of your programme.
To use the button is as simple as using a normal Pure Basic button and follws the same rules.
After using the OpenWindow() function simply add an OnOffbutton with the following line of code.
OnOffButton(#OnOff1,10,10,90,25)
Only the positional information is used the width and height are ignored. This will create an OnOffButton at the coordinates 10,10.
You can set the original state of the button or change its state any time during programme execution by using the SetOnOffButtonState() Procedure. The example programme uses this to set the original state of the button after creation:-
SetOnOffButtonState(#OnOff1,#True)
This will show the button as "On" when run.
You can also get the state of the button at anytime during programme execution by using the GetOnOffButtonState(Gadget.i) procedure where (Gadget.i) is replaced by the variable or constant used to create the button.
Two events are reported by the button. These are:-
#StateIsOn
#StateIsOff
when the state of the button is changed by the programme user one of the events will be reported. These events are captured in your programme by using the EventData() function after selecting which gadget has raised the event with Select EventGadget() as below:-
Select EventGadget()
Case #OnOff1
Select EventData()
Case OnOffButton::#StateIsOn
Debug "Button 1 Is On"
Case OnOffButton::#StateIsOff
Debug "Button 1 Is Off"
EndSelect
This is only a portion of code to see the full operation look at the example programme included.