Salut
Voila je cherche comment limiter la saisie de caracteres dans un stringgadget
sans passer par keyboard si possible.
Merci
[Resolu] stringgadget comment limiter la saisie ?
[Resolu] stringgadget comment limiter la saisie ?
Dernière modification par coxco le lun. 01/sept./2008 9:57, modifié 1 fois.
Bonjour,
Il suffit de faire comme ceci :
#StringGadget => Numéro du gadget
10 => La limite en caractères
Il suffit de faire comme ceci :
Code : Tout sélectionner
SendMessage_(GadgetID(#StringGadget), #EM_LIMITTEXT, 10, 0)
10 => La limite en caractères
le meme chose un peut plus long, mais sans API !! (donc compatible Linux) 

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
;