BindEvent(Event, @Callback() [, Window [, Object [, EventType]]])
Bind an 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(), live window resize, etc.). An event can be unbound with UnbindEvent().


Event The event to bind. For a full list of events, see WindowEvent(). Custom events are also supported, when using PostEvent().
@Callback() The callback procedure to call when the event occurs. It has to be declared like this:
  Procedure EventHandler()
    ; Code
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.
Window (optional) The #Window number to bind the event to. The event will be dispatched only when occurring on this window. #PB_All can be specified to bind the event to all windows (if specified, 'Object' and 'EventType' parameters have to be set to #PB_All as well).
Object (optional) The object number to bind the event to. It can be a gadget, menuitem or systray number. #PB_All can be used to bind the event to any objects (if specified, 'EventType' parameter has to be set to #PB_All as well).
EventType (optional) The event type to bind the event to. For a full list of supported type, see EventType(). #PB_All can be used to bind the event to any type.

Return value



  Procedure SizeWindowHandler()
    Debug "Size event on window #" + EventWindow()
    ; Resize the gadget to fit the new window dimensions
    ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(EventWindow())-20, WindowHeight(EventWindow())-20)
  OpenWindow(0, 100, 100, 200, 200, "Live resize test", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
  EditorGadget(0, 10, 10, 180, 180)
  BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow

See Also

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

Supported OS


<- AddWindowTimer() - Window Index - CloseWindow() ->