Centrer le contenu d'une barre d'outils

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
anissa
Messages : 136
Inscription : mer. 13/oct./2010 15:43

Centrer le contenu d'une barre d'outils

Message par anissa »

Bonjour,

Pensez-vous qu'il serait possible de centrer (ou définir la colonne) d'un gadget d'une barre d'outils?

Exemple:

Code : Tout sélectionner

If CreateToolBar(0, WindowID(0))
   ToolBarImageButton(5, "Icone1.ico")
   ToolBarImageButton(5, "Icone2.ico")
   ToolBarImageButton(5, "Icone3.ico")
EndIf
Dans cet exemple, mes 3 icones seront alignées à l'extrême gauche. Serait-il possible de les mettre un peu plus à droite ?

Merci de votre aide

Anissa
anissa
Messages : 136
Inscription : mer. 13/oct./2010 15:43

Re: Centrer le contenu d'une barre d'outils

Message par anissa »

Merci de corriger svp: l'image id de 1 à 3 des icones..

(erreur de frappe !)

Code : Tout sélectionner

 If CreateToolBar(0, WindowID(0))
   ToolBarImageButton(1, "Icone1.ico")
   ToolBarImageButton(2, "Icone2.ico")
   ToolBarImageButton(3, "Icone3.ico")
EndIf
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Centrer le contenu d'une barre d'outils

Message par falsam »

j'utilise une astuce qui fait bricolage mais qui fonctionne.

Code : Tout sélectionner

Enumeration
  #MainForm
  #Barico
EndEnumeration

Procedure MainFormShow()
  OpenWindow(#MainForm,0,0,400,400,"Barre Icone",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  CreateToolBar(#Barico, WindowID(#MainForm))
  For i=0 To 6
    ToolBarImageButton(i, ImageID( CreateImage(#PB_Any,10,10)))
    DisableToolBarButton(#Barico, i, #True)
  Next
  
  ToolBarStandardButton(0, #PB_ToolBarIcon_New)
  ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
  ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
  
EndProcedure

MainFormShow()

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget

    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Centrer le contenu d'une barre d'outils

Message par Kwai chang caine »

Ou peut etre ce code de TROND :roll:

Code : Tout sélectionner

Procedure StopToolbarAutoAlign(Toolbar) 
  T = ToolBarID(0) 
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NODIVIDER) 
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NOPARENTALIGN) 
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NORESIZE) 
EndProcedure 

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu) 
CreateToolBar(0, WindowID(0)) 
ToolBarStandardButton(0, 0) 
ToolBarStandardButton(0, 1) 
ToolBarStandardButton(0, 2) 
ToolBarStandardButton(0, 3) 


StopToolbarAutoAlign(0) 
T = ToolBarID(0) 

MoveWindow_(ToolBarID(0), 100, 100, 512, 22, 1) 

Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      Break 
  EndSelect 
ForEver
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Centrer le contenu d'une barre d'outils

Message par falsam »

ça fait moins bricolage que mon astuce :p Allez ..... j'enfourne ce code dans ma malle.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
anissa
Messages : 136
Inscription : mer. 13/oct./2010 15:43

Re: Centrer le contenu d'une barre d'outils

Message par anissa »

Merci de votre aide, je vais essayer ce soir les deux méthodes (bien que la deuxième me semble plus indiquée).

Je vous mettrais au courant des résultats

Anissa
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Re: Centrer le contenu d'une barre d'outils

Message par jbernard13 »

Merci pour le code
je le recupere
Jbernard13
Répondre