Outil de Saisie d'un StringGadget

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Cagou-77
Messages : 79
Inscription : dim. 15/août/2004 13:27

Outil de Saisie d'un StringGadget

Message par Cagou-77 »

Salut à tous

je vient de me créer un outil pour la saisie des StringGadgets si ca peut
servir aux membres ou si ca peut-etre amélioré faite le moi savoir .

c'est plus clair pour l'utilistateur pour repérer le focus d'un StringGadget

vos critiques seront les biens venues

Cagou-77

Code : Tout sélectionner

; ; Utilitaire Crée par Cagou-77 le 14/08/2005

Enumeration
  #button_annule
  #WindArt
  #FrameZrecC
  ;- Constantes Fontes
  #Arial8
  #Arial8Bold
  #Arial10
  #Arial16
  #Arial14
  #Arial12
  #Arial24
  #Arial48
EndEnumeration

LoadFont( #Arial8, "Arial", 8 )
LoadFont( #Arial8Bold, "Arial", 8, #PB_Font_Bold )
LoadFont( #Arial10, "Arial", 10, #PB_Font_Bold )
LoadFont( #Arial12, "Arial", 12, #PB_Font_Bold )
LoadFont( #Arial14, "Arial", 14, #PB_Font_Bold )
LoadFont( #Arial16, "Arial", 16, #PB_Font_Bold )
LoadFont( #Arial24, "Arial", 24, #PB_Font_Bold )
LoadFont( #Arial48, "Arial", 48, #PB_Font_Bold )

Structure Gadget
  IDLibelle.l
  IDString.l
  IDStringFocus.l
EndStructure

NewList LstGadget.Gadget()

Procedure GadgetSaisie( X.l, Y.l, L.l, H.l, Text.s, Opt.l )
  AddElement( LstGadget() )
  LgText.l = ( Len( Text ) * 7 )
  LstGadget()\IDLibelle = TextGadget( #PB_ANY, X, Y, LgText, H, Text, 0 )
  LstGadget()\IDString = StringGadget( #PB_ANY, (X + LgText), Y, L, H, "", 0 )
  LstGadget()\IDStringFocus = #FALSE
  UseFont(#Arial8)
  SetGadgetFont( LstGadget()\IDLibelle, FontID())
  SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244))
  SetGadgetColor(LstGadget()\IDString, RGB(65, 20, 92), RGB(218, 236, 245))
EndProcedure

Procedure ColoriageBis( GadgetID.l)
  ForEach LstGadget()
    If LstGadget()\IDStringFocus = #TRUE
      SetGadgetFont( LstGadget()\IDLibelle, FontID())
      SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244))
      SetGadgetColor(LstGadget()\IDString, RGB(65, 20, 92), RGB(218, 236, 245))
      LstGadget()\IDStringFocus = #FALSE
    EndIf
  Next
  ForEach LstGadget()
    If LstGadget()\IDString = GadgetID
      UseFont(#Arial8Bold)
      SetGadgetFont( LstGadget()\IDLibelle, FontID())
      SetGadgetColor(LstGadget()\IDLibelle, RGB(72, 73, 125), RGB(233, 245, 244))
      SetGadgetColor(LstGadget()\IDString, RGB(236, 44, 28), RGB(247, 247, 216))
      LstGadget()\IDStringFocus = #TRUE
      Break
    EndIf
  Next
  UseFont(#Arial8)
EndProcedure

Procedure TestColoriage()
  If OpenWindow(#WindArt, 0, 0, 400, 300, #PB_Window_ScreenCentered, "Test de Coloriage du StringGadget Focus")
    SetClassLong_(WindowID(#WindArt), #GCL_HBRBACKGROUND, CreateSolidBrush_(RGB(233, 245, 244)))
    If CreateGadgetList(WindowID())
      Frame3DGadget(#FrameZrecC, 10, 5, 380, 280, "")
      GadgetSaisie( 15, 30, 130, 18, "Nom :", 0 )
      GadgetSaisie( 15, 60, 130, 18, "Prenom :", 0 )
      GadgetSaisie( 95, 120, 70, 18, "Date :", 0 )
    EndIf
    Repeat
      Event = WaitWindowEvent()
      WindowID = EventWindowID()
      EventType = EventType()
      GadgetID = EventGadgetID()
      Select Event
        Case #PB_EventGadget
          ColoriageBis( GadgetID )
      EndSelect
      Select event
        Case #PB_EventGadget
          Select GadgetID
              
            Case #button_annule : fermer_window_1 = 1
          EndSelect
      EndSelect
    Until fermer_window_1 = 1
    CloseWindow(#WindArt)
    While WindowEvent() : Wend
  EndIf
EndProcedure

TestColoriage()

End
dlolo
Messages : 118
Inscription : ven. 18/févr./2005 16:29

Message par dlolo »

Salut (voisin),

Code : Tout sélectionner

SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244)) 
Erreur ligne 41 setgadgetcolor() is not a function...

Quelle lib ?
Avatar de l’utilisateur
Jacobus
Messages : 1559
Inscription : mar. 06/avr./2004 10:35
Contact :

Message par Jacobus »

C'est effectivement une bonne idée. :)

@dlolo : la Lib est celle de Denis MoreGadgetColor téléchargeable sur son site.

NB : Pour ceux qui ne l'auraient pas remarqué, il y en a peut-être, une fonction native des StringGadget => Clic droit à l'intérieur donne un popupmenu contenant les fonctions d'édition de base. trés utile pour les saisies répétitives.

@+
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
dlolo
Messages : 118
Inscription : ven. 18/févr./2005 16:29

Message par dlolo »

merci.
Cagou-77
Messages : 79
Inscription : dim. 15/août/2004 13:27

Message par Cagou-77 »

Code légerement modifier :


Cagou-77

Code : Tout sélectionner

; Utilitaire Crée par Cagou-77 le 14/08/2005

Enumeration
  #button_annule
  #WindArt
  #FrameZrecC

  ;- Constantes Fontes
  #Arial8
  #Arial8Bold
  #Arial10
  #Arial16
  #Arial14
  #Arial12
  #Arial24
  #Arial48
EndEnumeration

LoadFont( #Arial8, "Arial", 8 )
LoadFont( #Arial8Bold, "Arial", 8, #PB_Font_Bold )
LoadFont( #Arial10, "Arial", 10, #PB_Font_Bold )
LoadFont( #Arial12, "Arial", 12, #PB_Font_Bold )
LoadFont( #Arial14, "Arial", 14, #PB_Font_Bold )
LoadFont( #Arial16, "Arial", 16, #PB_Font_Bold )
LoadFont( #Arial24, "Arial", 24, #PB_Font_Bold )
LoadFont( #Arial48, "Arial", 48, #PB_Font_Bold )

Structure Gadget
  IDLibelle.l
  IDString.l
  IDStringFocus.l
EndStructure

NewList LstGadget.Gadget()

Procedure.l GadgetSaisie( X.l, Y.l, L.l, H.l, Text.s, Opt.l )
  AddElement( LstGadget() )
  LgText.l = ( Len( Text ) * 7 )
  LstGadget()\IDLibelle = TextGadget( #PB_ANY, X, Y, LgText, H, Text, 0 )
  LstGadget()\IDString = StringGadget( #PB_ANY, (X + LgText), Y, L, H, "", 0 )
  LstGadget()\IDStringFocus = #FALSE
  UseFont(#Arial8)
  SetGadgetFont( LstGadget()\IDLibelle, FontID())
  SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244))
  SetGadgetColor(LstGadget()\IDString, RGB(65, 20, 92), RGB(218, 236, 245))
  ProcedureReturn LstGadget()\IDString
EndProcedure

Procedure ColoriageBis( GadgetID.l)
  ForEach LstGadget()
    If LstGadget()\IDStringFocus = #TRUE
      SetGadgetFont( LstGadget()\IDLibelle, FontID())
      SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244))
      SetGadgetColor(LstGadget()\IDString, RGB(65, 20, 92), RGB(218, 236, 245))
      LstGadget()\IDStringFocus = #FALSE
    EndIf
  Next
  ForEach LstGadget()
    If LstGadget()\IDString = GadgetID
      UseFont(#Arial8Bold)
      SetGadgetFont( LstGadget()\IDLibelle, FontID())
      SetGadgetColor(LstGadget()\IDLibelle, RGB(72, 73, 125), RGB(233, 245, 244))
      SetGadgetColor(LstGadget()\IDString, RGB(236, 44, 28), RGB(247, 247, 216))
      SetGadgetFont( LstGadget()\IDString, FontID())
      LstGadget()\IDStringFocus = #TRUE
      Break
    EndIf
  Next
  UseFont(#Arial8)
EndProcedure

Procedure TestColoriage()
  If OpenWindow(#WindArt, 0, 0, 400, 300, #PB_Window_ScreenCentered, "Test de Coloriage du StringGadget Focus")
    SetClassLong_(WindowID(#WindArt), #GCL_HBRBACKGROUND, CreateSolidBrush_(RGB(233, 245, 244)))
    If CreateGadgetList(WindowID())
      Frame3DGadget(#FrameZrecC, 10, 5, 380, 280, "")
      ButtonGadget(#button_annule,250,240,100,30,"Quitter")
      Nom.l    = GadgetSaisie( 15, 30, 130, 18, "Nom :", 0 )
      Prenom.l = GadgetSaisie( 15, 60, 130, 18, "Prenom :", 0 )
      Date.l   = GadgetSaisie( 95, 120, 70, 18, "Date :", 0 )
    EndIf
    Repeat
      Event = WaitWindowEvent()
      WindowID = EventWindowID()
      EventType = EventType()
      GadgetID = EventGadgetID()
      If Event = #PB_EventGadget
         ColoriageBis( GadgetID )
      EndIf
      Select event
        Case #PB_EventGadget
          Select GadgetID
              
            Case #button_annule : fermer_window_1 = 1
            
              Debug GetGadgetText( Nom )
              Debug GetGadgetText( Prenom )
              Debug GetGadgetText( Date )
              
          EndSelect
      EndSelect
    Until fermer_window_1 = 1
    CloseWindow(#WindArt)
;    While WindowEvent() : Wend
  EndIf
EndProcedure

TestColoriage()

End
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Message par Anonyme2 »

Les couleurs me plaisent bien, je vais les utiliser pour un de mes outils :D
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

SetGadgetColor; c'est quelle Lib, je la vois pas sur le Site de Denis.

Denis,
Pas évident d'installer tes Libs, pourtant le soft s'occupe de tout me diras tu; oui mais quand on a plusieurs versions d'installées. :roll:
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Message par Anonyme2 »

nico a écrit :SetGadgetColor; c'est quelle Lib, je la vois pas sur le Site de Denis.

Denis,
Pas évident d'installer tes Libs, pourtant le soft s'occupe de tout me diras tu; oui mais quand on a plusieurs versions d'installées. :roll:
J'avais supprimé le lien car je voulais la reprendre car j'avais quelques soucis avec mais elle est toujours sur mon site ici

A mettre dans le dossier des libs, pas de doc, pas d'installeur. Sur le forum, il y a un post qui explique la syntaxe dans la rubrique annoce il me semble

J'ai déjà réfléchi sur le problème des versions mais je n'ai pas donné suite. :oops:
Dernière modification par Anonyme2 le dim. 14/août/2005 19:46, modifié 2 fois.
Cagou-77
Messages : 79
Inscription : dim. 15/août/2004 13:27

Message par Cagou-77 »

Nouvelle Version

Code : Tout sélectionner

; Utilitaire Crée par Cagou-77 le 14/08/2005

Enumeration
  #button_annule
  #WindArt
  #FrameZrecC

  ;- Constantes Fontes
  #Arial8
  #Arial8Bold
  #Arial10
  #Arial16
  #Arial14
  #Arial12
  #Arial24
  #Arial48
EndEnumeration

LoadFont( #Arial8, "Arial", 8 )
LoadFont( #Arial8Bold, "Arial", 8, #PB_Font_Bold )
LoadFont( #Arial10, "Arial", 10, #PB_Font_Bold )
LoadFont( #Arial12, "Arial", 12, #PB_Font_Bold )
LoadFont( #Arial14, "Arial", 14, #PB_Font_Bold )
LoadFont( #Arial16, "Arial", 16, #PB_Font_Bold )
LoadFont( #Arial24, "Arial", 24, #PB_Font_Bold )
LoadFont( #Arial48, "Arial", 48, #PB_Font_Bold )

Structure Gadget
  IDLibelle.l
  IDString.l
  IDStringFocus.l
EndStructure

NewList LstGadget.Gadget()

Procedure.l Empty( Valeur.s )
  If Len( LTrim( Valeur ) ) > 0
    ProcedureReturn #FALSE
  Else
    ProcedureReturn #TRUE
  EndIf
EndProcedure

Procedure.l NotEmpty( Valeur.s )
  If Len( LTrim( Valeur ) ) = 0
    ProcedureReturn #FALSE
  Else
    ProcedureReturn #TRUE
  EndIf
EndProcedure

Procedure.l GadgetSaisie( X.l, Y.l, L.l, H.l, Text.s, Opt.l )
  AddElement( LstGadget() )
  If NotEmpty( Text ) 
     LgText.l = ( Len( Text ) * 7 )
     LstGadget()\IDLibelle = TextGadget( #PB_ANY, X, Y, LgText, H, Text, 0 )
     X1 = (X + LgText)
     UseFont(#Arial8)
     SetGadgetFont( LstGadget()\IDLibelle, FontID())
     SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244))
  Else
     X1 = X
  EndIf
  LstGadget()\IDString = StringGadget( #PB_ANY, X1, Y, L, H, "", 0 )
  LstGadget()\IDStringFocus = #FALSE
  SetGadgetColor(LstGadget()\IDString, RGB(65, 20, 92), RGB(218, 236, 245))
  ProcedureReturn LstGadget()\IDString
EndProcedure

Procedure ColoriageBis( GadgetID.l)
  ForEach LstGadget()
    If LstGadget()\IDStringFocus = #TRUE
      If LstGadget()\IDLibelle > 0
         SetGadgetFont( LstGadget()\IDLibelle, FontID())
         SetGadgetColor(LstGadget()\IDLibelle, RGB(161, 87, 22), RGB(233, 245, 244))
      EndIf
      SetGadgetColor(LstGadget()\IDString, RGB(65, 20, 92), RGB(218, 236, 245))
      LstGadget()\IDStringFocus = #FALSE
    EndIf
  Next
  ForEach LstGadget()
    If LstGadget()\IDString = GadgetID
      UseFont(#Arial8Bold)
      If LstGadget()\IDLibelle > 0
         SetGadgetFont( LstGadget()\IDLibelle, FontID())
         SetGadgetColor(LstGadget()\IDLibelle, RGB(72, 73, 125), RGB(233, 245, 244))
      EndIf
      SetGadgetColor(LstGadget()\IDString, RGB(236, 44, 28), RGB(247, 247, 216))
      SetGadgetFont( LstGadget()\IDString, FontID())
      LstGadget()\IDStringFocus = #TRUE
      Break
    EndIf
  Next
  UseFont(#Arial8)
EndProcedure

Procedure TestColoriage()
  If OpenWindow(#WindArt, 0, 0, 400, 300, #PB_Window_ScreenCentered, "Test de Coloriage du StringGadget Focus")
    SetClassLong_(WindowID(#WindArt), #GCL_HBRBACKGROUND, CreateSolidBrush_(RGB(233, 245, 244)))
    If CreateGadgetList(WindowID())
      Frame3DGadget(#FrameZrecC, 10, 5, 380, 280, "")
      ButtonGadget(#button_annule,250,240,100,30,"Quitter")
      Nom.l     = GadgetSaisie( 15, 30, 130, 18, "Nom :", 0 )
      Prenom.l  = GadgetSaisie( 15, 60, 130, 18, "Prenom :", 0 )
      Date.l    = GadgetSaisie( 95, 120, 70, 18, "Date :", 0 )
      Adresse.l = GadgetSaisie( 15, 160, 120, 18, "", 0 )
    EndIf
    Repeat
      Event = WaitWindowEvent()
      WindowID = EventWindowID()
      EventType = EventType()
      GadgetID = EventGadgetID()
      If Event = #PB_EventGadget
         ColoriageBis( GadgetID )
      EndIf
      Select event
        Case #PB_EventGadget
          Select GadgetID
              
            Case #button_annule : fermer_window_1 = 1
            
              Debug GetGadgetText( Nom )
              Debug GetGadgetText( Prenom )
              Debug GetGadgetText( Date )
              
          EndSelect
      EndSelect
    Until fermer_window_1 = 1
    CloseWindow(#WindArt)
;    While WindowEvent() : Wend
  EndIf
EndProcedure

TestColoriage()

End
Répondre