BindGadgetEvent()

语法

BindGadgetEvent(#Gadget, @Callback() [, EventType])
概要
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().

参数

#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.
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.

返回值

无.

示例

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

参阅

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

已支持操作系统

所有

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