Page 1 sur 1

[Resolu] stringgadget comment limiter la saisie ?

Publié : mar. 19/août/2008 13:30
par coxco
Salut

Voila je cherche comment limiter la saisie de caracteres dans un stringgadget
sans passer par keyboard si possible.

Merci

Publié : mar. 19/août/2008 13:41
par Mytic
Bonjour,
Il suffit de faire comme ceci :

Code : Tout sélectionner

SendMessage_(GadgetID(#StringGadget), #EM_LIMITTEXT, 10, 0)
#StringGadget => Numéro du gadget
10 => La limite en caractères

Merci

Publié : mar. 19/août/2008 13:43
par coxco
Super Merci

:)

Publié : mar. 19/août/2008 14:05
par Ar-S
hum c'est bon à savoir, merci Mytic

Publié : mar. 19/août/2008 16:06
par Backup
le meme chose un peut plus long, mais sans API !! (donc compatible Linux) :D

Code : Tout sélectionner


; Codé par Dobro 
; en purebasic 4.00
;- Window Constants
;
Enumeration
      #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
      #String_0
      #Text_0
EndEnumeration


Procedure Open_Window_0()
      If OpenWindow(#Window_0, 216, 0, 600, 300, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
            If CreateGadgetList(WindowID(#Window_0))
                  StringGadget(#String_0, 50, 30, 150, 20, "",#PB_String_Numeric )
                  TextGadget(#Text_0, 50, 60, 140, 20, "Limité a 6 caracteres chiffre")
                  
            EndIf
      EndIf
EndProcedure

Open_Window_0()

Repeat ; Start of the event loop 
      Event = WaitWindowEvent() ;  
      WindowID = EventWindow() ; 
      GadgetID = EventGadget() ;  
      EventType = EventType() ;  
      ; 
      If Event = #PB_Event_Gadget 
            If GadgetID = #String_0
                  text$=GetGadgetText(#String_0)
                  If Len( text$)>6 
                        text$= Left(text$,6)
                        StringGadget(#String_0, 50, 30, 150, 20, "",#PB_String_ReadOnly|#PB_String_Numeric  ) 
                        StringGadget(#String_0, 50, 30, 150, 20, "",#PB_String_Numeric   )
                        SetGadgetText(#String_0, text$)
                  EndIf 
            EndIf 
      EndIf 
Until Event = #PB_Event_CloseWindow ; End of the event loop

End
;

Publié : mar. 19/août/2008 17:12
par coxco
C'est pas mal non plus
merci