Page 1 sur 1

Utiliser ResizeWindows pour placer centrer un panel sans modifier sa taille

Publié : dim. 27/juil./2025 17:51
par Philippe_GEORGES
Bonjour à tous,

Dans une fenêtre, j'ai placé un PanelGadget qui prends toute la place en usage normal (fenêtre non agrandie).

Je voudrais pouvoir centrer ce gadget dans la fenêtre, si cette fenêtre est agrandie, SANS MODIFIER SA TAILLE, simplement le centrer.

Mais comment faire ? ResizeGadget sais faire, mais il augmente la taille du Panel en le centrant.

Ca doit être simple, mais je ne trouve pas une solution fiable.

Merci d'avance,

Phil

Re: Utiliser ResizeWindows pour placer centrer un panel sans modifier sa taille

Publié : dim. 27/juil./2025 18:23
par SPH
Pourrais tu nous partager un petit code ? :idea:

Re: Utiliser ResizeWindows pour placer centrer un panel sans modifier sa taille

Publié : dim. 27/juil./2025 21:19
par Mindphazer
Hello Phil,
quelque chose comme ça ?

Code : Tout sélectionner

Enumeration 
  #MainWindow
  #Panel
EndEnumeration

Procedure OpenMainWindow(x = 0, y = 0, width = 430, height = 300)
  OpenWindow(#MainWindow, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  PanelGadget(#Panel, 10, 20, 410, 270)
  AddGadgetItem(#Panel, -1, "Tab 1")
  CloseGadgetList()
EndProcedure

Procedure ResizeGadgetsMainWindow()
  PanelX = WindowWidth(#MainWindow) / 2 - GadgetWidth(#Panel) / 2
  PanelY = WindowHeight(#MainWindow) / 2 - GadgetHeight(#Panel) / 2
  ResizeGadget(#Panel, PanelX, PanelY, #PB_Ignore, #PB_Ignore)
EndProcedure

OpenMainWindow()
BindEvent(#PB_Event_SizeWindow, @ResizeGadgetsMainWindow())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Utiliser ResizeWindows pour placer centrer un panel sans modifier sa taille

Publié : dim. 27/juil./2025 21:27
par Philippe_GEORGES
Ben oui, incroyable !! Un grand merci !

Voici le code qui me fallait, je me dis que je n'avais pas assez réfléchi !!

Merci du temps passé pour me répondre !

Code : Tout sélectionner

Enumeration 
  #MainWindow
  #Panel
EndEnumeration

Declare ResizeGadgetsMainWindow()

Procedure OpenMainWindow(x = 0, y = 0, width = 430, height = 300)
  OpenWindow(#MainWindow, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget)
  PanelGadget(#Panel, 10, 20, 410, 270)
  AddGadgetItem(#Panel, -1, "Tab 1")
  CloseGadgetList()
  BindEvent(#PB_Event_SizeWindow, @ResizeGadgetsMainWindow())
EndProcedure

Procedure ResizeGadgetsMainWindow()
  PanelX = WindowWidth(#MainWindow) / 2 - GadgetWidth(#Panel) / 2
  PanelY = WindowHeight(#MainWindow) / 2 - GadgetHeight(#Panel) / 2
  ResizeGadget(#Panel, PanelX, PanelY, #PB_Ignore, #PB_Ignore)
EndProcedure

OpenMainWindow()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Phil