BindGadgetEvent()

Syntax

BindGadgetEvent(#Gadget, @Callback() [, EventType])
Description
Bind a gadget event to a callback. It's an additional way to handle events in PureBasic, which works without problem with the regulars WindowEvent() / WaitWindowEvent() commands. It also allows to have real-time event notifications as the callback can be invoked as soon as the event occurs (useful for ScrollBarGadget(), ScrollAreaGadget() etc.). A gadget event can be unbinded with UnbindGadgetEvent().

Parameters

#Gadget The gadget to bind the event to.
@Callback() The callback procedure to call when the event occurs. It has to be declared like this:
  Procedure EventHandler()
    ; Code
  EndProcedure
Regular functions like EventGadget(), EventWindow(), EventMenu(), EventType() and EventData() are available within the callback to get more information about the event.

Note: WindowEvent() and WaitWindowEvent() should never be called from inside the callback or the program can be locked or have wrong behavior.
EventType (optional) The event type to bind the event to. For a full list of supported types, see EventType(). #PB_All can be used to bind the event to any type.

Return value

None.

Example

  Procedure ButtonHandler()
    Debug "Button click event on gadget #" + EventGadget()
  EndProcedure
  
  OpenWindow(0, 100, 100, 200, 90, "Click test", #PB_Window_SystemMenu)
  
  ButtonGadget(0, 10, 10, 180, 30, "Click me")
  BindGadgetEvent(0, @ButtonHandler())
  
  ButtonGadget(1, 10, 50, 180, 30, "Click me")
  BindGadgetEvent(1, @ButtonHandler())
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow

See Also

BindGadgetEvent(), BindMenuEvent(), UnbindEvent(), WindowEvent(), WaitWindowEvent()

Supported OS

All

<- AddGadgetItem() - Gadget Index - ButtonGadget() ->