Home
Products
Community
Manuals
Contact
Login or Signup

BlitzMax Docs -> C -> CreateButton

CreateButton:TGadget(label$,x,y,w,h,group:TGadget,style=BUTTON_PUSH)

Returns:

Nothing.

Description:

Create a Button gadget.

A Button generates an EVENT_GADGETACTION TEvent whenever it is pushed.

StyleMeaning
BUTTON_PUSHStandard push button.
BUTTON_CHECKBOXA check box button that displays a tick when it's state is True.
BUTTON_RADIOA radio button is accompanied by a small circular indicator, filled when it's state is True.
BUTTON_OKStandard push button that is also activated when the user presses the RETURN key.
BUTTON_CANCELStandard push button that is also activated when the user presses the ESCAPE key.

On certain platforms, the BUTTON_PUSH flag can be combined with either BUTTON_CHECKBOX or BUTTON_RADIO to obtaina button looking similar to standard push-buttons, but mimicking the behaviour of the checkbox or radio button.

See Also: SetGadgetText, SetButtonState, ButtonState and SetGadgetPixmap.

Example:

' createbutton.bmx

Import MaxGui.Drivers

Strict 

Global window:TGadget = CreateWindow("MaxGUI Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
	CreateButton("Std. Button",10,10,120,30,window,BUTTON_PUSH)
	CreateButton("OK Button",140,10,120,30,window,BUTTON_OK)
	CreateButton("Cancel Button",270,10,120,30,window,BUTTON_CANCEL)

Global panel:TGadget[4]
	panel[0]=CreatePanel(10,50,380,60,window,PANEL_GROUP,"Checkbox")
		FillPanelWithButtons(panel[0], BUTTON_CHECKBOX, "Checkbox")
	panel[1]=CreatePanel(10,120,380,60,window,PANEL_GROUP,"Checkbox (with Push Button Style)")
		FillPanelWithButtons(panel[1], BUTTON_CHECKBOX|BUTTON_PUSH, "Toggle")
	panel[2]=CreatePanel(10,190,380,60,window,PANEL_GROUP,"Radio Buttons")
		FillPanelWithButtons(panel[2], BUTTON_RADIO, "Option ")
	panel[3]=CreatePanel(10,260,380,60,window,PANEL_GROUP,"Radio Buttons (with Push Button Style)")
		FillPanelWithButtons(panel[3], BUTTON_RADIO|BUTTON_PUSH, "Option")

Repeat
	Select WaitEvent()
		Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
			End
		Case EVENT_GADGETACTION
			Print "EVENT_GADGETACTION~n" + ..
			"GadgetText(): ~q" + GadgetText(TGadget(EventSource())) + "~q ~t " + ..
			"ButtonState(): "+ ButtonState(TGadget(EventSource()))
	EndSelect
Forever

Function FillPanelWithButtons( pPanel:TGadget, pStyle%, pText$ = "Button" )
	Local buttonwidth% = (pPanel.width-10)/3
	For Local i% = 0 Until 3
		CreateButton( pText + " " + (i+1), 5+(i*buttonwidth), 5, buttonwidth-10, 26, pPanel, pStyle )
	Next
EndFunction 

Comments

Mark Tiffany(Posted 1+ years ago)
Button gadgets are recommended to be 28 pixels tall in order to operate correctly on all platforms, although note that on linux (and possibly macos), Ok & Cancel buttons should be at least 34 pixels tall to avoid the standard icons being chopped.

Default icons are provided by the OS for some gadgets on Linux & possibly Macos, but not win32.

Win32 - None
Linux/GTK - Ok & Cancel
Linux/FLTK - Ok
Macos - Unknown??


BlitzMax Manual Forum

Blitz3D Equivalent Command