The event works without problems.
But you have to bind the gadget event when you bind the event size window. Otherwise the event only comes after the mouse is released.
Code: Select all
;-TOP
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
EndEnumeration
Enumeration Gadgets
#MainScrollArea
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Procedure DoEventResizeScrollArea()
Debug "Bind Event: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
; Resize gadgets
ResizeGadget(#MainScrollArea, 0, 0, dx, dy)
EndProcedure
; ----
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
ScrollAreaGadget(#MainScrollArea, 0, 0, dx, dy, dx * 2, dy * 3)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
BindGadgetEvent(#MainScrollArea, @DoEventResizeScrollArea(), #PB_EventType_Resize)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainScrollArea
Select EventType()
Case #PB_EventType_Resize
;Debug "Main Loop: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Structured event processing is important in order to query events only when they are valid.
EventGadget() and EventType() valid after an event #PB_Gadget_Event. EventTypes valid see after description of the gadget. EventTimer() after an event #PB_Event_Timer, etc.