tu les connais pas , ils sont difficile !Dorian a écrit :48 c'est déjà plus que bien ^^


ps : je viens de corriger un petit truc , maintenant ça doit allé

(toujours avec la limitation 48 et text un peut trop long ...)
Code : Tout sélectionner
Procedure AutosizeCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Protected WndProc.l, Gadget.l, Size.Size
Protected Text.s, Field.s, Count.l, i.l, w.l, h.l
WndProc = GetProp_(WindowID, "AutosizeWndProc")
If Message = #WM_CTLCOLORSTATIC And GetProp_(lParam, "AutosizeValue")
Gadget = GetDlgCtrlID_(lParam)
Text = GetGadgetText(Gadget)
;vire les retours charriot
Text = ReplaceString(Text, #CRLF$, #LF$)
Text = ReplaceString(Text, #CR$, #LF$)
Count = CountString(Text, #LF$) + 1
For i = 1 To Count
Field = StringField(Text, i, #LF$)
GetTextExtentPoint32_(wParam, Field, Len(Field), Size)
If w < Size\cx
w = Size\cx
Size\cx = 0
EndIf
Next i
h = Size\cy * Count
ResizeGadget(Gadget, #PB_Default, #PB_Default, w, h)
EndIf
ProcedureReturn CallWindowProc_(WndProc, WindowID, Message, wParam, lParam)
EndProcedure
Procedure SetTextGadgetAutosize(TextGadget.l, Autosize.l)
Protected GadgetID.l, WindowID.l, WndProc.l
If IsGadget(TextGadget)
GadgetID = GadgetID(TextGadget)
SetProp_(GadgetID, "AutosizeValue", Autosize)
WindowID = GetParent_(GadgetID)
If GetProp_(WindowID, "AutosizeWndProc") = #Null
WndProc = SetWindowLong_( WindowID, #GWL_WNDPROC, @AutosizeCallback() )
SetProp_(WindowID, "AutosizeWndProc", WndProc)
EndIf
InvalidateRect_(GadgetID, #Null, #True)
EndIf
EndProcedure
If OpenWindow(0,0,0,270,160,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TextGadget") And CreateGadgetList(WindowID(0))
label.s = "Auto size"
label + #CRLF$ + "ceci est un exemple"
label + #CRLF$ + "c'est simple"
TextGadget(0, 10, 10, 250, 20, label)
TextGadget(1, 10, 50, 250, 20, label)
;change de police pour le fun
LoadFont(0, "Verdana", 18)
SetGadgetFont(0, UseFont(0))
SetGadgetFont(1, UseFont(0))
;change la couleur de la fenetre pour avoir un visuel
hBrush = CreateSolidBrush_($FFFFFF)
SetClassLong_(WindowID(), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(), #Null, #True)
;autosize le 2e gadget
SetTextGadgetAutosize(1, #True)
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(hBrush)
EndIf
Dans mon exemple c'est le textgadget qui s'auto dimensionneDobro a écrit :j'ai changer la ligne
"LoadFont(0, "Verdana", 18)" par "LoadFont(0, "Verdana", 48)"
la fenetre ne se redimentionne pas !!![]()
mon system ne marche pas si mal finalement !!
Code : Tout sélectionner
If OpenWindow(0,0,0,270,160,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TextGadget") And CreateGadgetList(WindowID(0))
label.s = "Auto size"
label + #CRLF$ + "ceci est un exemple"
label + #CRLF$ + "c'est simple"
TextGadget(0, 0, 00, 250, 20, label)
;change de police pour le fun
LoadFont(0, "Verdana", 18)
SetGadgetFont(0, UseFont(0))
;autosize le gadget
SetTextGadgetAutosize(0, #True)
Repeat
If WindowWidth() <> GadgetWidth(0) Or WindowHeight() <> GadgetHeight(0)
ResizeWindow( GadgetWidth(0), GadgetHeight(0) )
EndIf
Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(hBrush)
EndIf
; PureBasic Visual Designer v3.92 build 1460
;- Window Constants
Declare Open_message(text$,taille)
Enumeration
#message
#Police
#Button_0
#Text_0
EndEnumeration
text$= "hello " + Chr (10)+ Chr (13)+ "comment vas tu ?" ; <----------------------------ICI ajoute du text
taille=8 ; <----------------------------ICI change la taille
Open_message(text$,taille)
; ******************* boucle principale ****************
Repeat ; Start of the event loop
Event = WaitWindowEvent () ; This line waits until an event is received from Windows
WindowID = EventWindowID () ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadgetID () ; Is it a gadget event?
EventType = EventType () ; The event type
If Event = #PB_EventGadget
If GadgetID = #Button_0
End
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
;**********************************
Procedure Open_message(text$,taille)
FontID = LoadFont ( #Police , "Comic Sans MS" , taille, #PB_Font_Bold )
long=( Len (text$)*taille)
If OpenWindow ( #message , 10, 10,long, 50+long/8, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar , "message" )
If CreateGadgetList ( WindowID ())
ButtonGadget ( #Button_0 , 0, WindowHeight ()-30, 60, 30, "ok" )
TextGadget ( #Text_0 , 30, (taille/8 ), 140+long, taille*200, text$)
SetGadgetFont ( #Text_0 , FontID )
EndIf
EndIf
EndProcedure
Dr. Dri a écrit :C'est risqué de se baser sur le nombre de caractères, les 'i' ne sont pas aussi longs que les 'm'Dobro a écrit :ouaip !ça marche ...
et que pense tu de cette exemple qui utilise l'autre methode ?
Dri
Code : Tout sélectionner
Procedure AutosizeCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Protected WndProc.l, Gadget.l, Size.Size
Protected Text.s, Field.s, Count.l, i.l, w.l, h.l
WndProc = GetProp_(WindowID, "AutosizeWndProc")
If Message = #WM_CTLCOLORSTATIC And GetProp_(lParam, "AutosizeValue")
Gadget = GetDlgCtrlID_(lParam)
Text = GetGadgetText(Gadget)
;vire les retours charriot
Text = ReplaceString(Text, #CRLF$, #LF$)
Text = ReplaceString(Text, #CR$, #LF$)
Count = CountString(Text, #LF$) + 1
For i = 1 To Count
Field = StringField(Text, i, #LF$)
GetTextExtentPoint32_(wParam, Field, Len(Field), Size)
If w < Size\cx
w = Size\cx
Size\cx = 0
EndIf
Next i
h = Size\cy * Count
ResizeGadget(Gadget, #PB_Default, #PB_Default, w, h)
EndIf
ProcedureReturn CallWindowProc_(WndProc, WindowID, Message, wParam, lParam)
EndProcedure
Procedure SetTextGadgetAutosize(TextGadget.l, Autosize.l)
Protected GadgetID.l, WindowID.l, WndProc.l
If IsGadget(TextGadget)
GadgetID = GadgetID(TextGadget)
SetProp_(GadgetID, "AutosizeValue", Autosize)
WindowID = GetParent_(GadgetID)
If GetProp_(WindowID, "AutosizeWndProc") = #Null
WndProc = SetWindowLong_( WindowID, #GWL_WNDPROC, @AutosizeCallback() )
SetProp_(WindowID, "AutosizeWndProc", WndProc)
EndIf
InvalidateRect_(GadgetID, #Null, #True)
EndIf
EndProcedure
If OpenWindow(0,0,0,270,160,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TextGadget") And CreateGadgetList(WindowID(0))
StringGadget(0, 10, 10, 250, 20, "")
TextGadget (1, 10, 40, 250, 20, "")
;change la couleur de la fenetre pour avoir un visuel
hBrush = CreateSolidBrush_($FFFFFF)
SetClassLong_(WindowID(), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(), #Null, #True)
;autosize le textgadget
SetTextGadgetAutosize(1, #True)
;donne le focus au stringgadget
ActivateGadget(0)
;synchronise les deux gadgets
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadgetID() = 0
If EventType() = #PB_EventType_Change
SetGadgetText(1, GetGadgetText(0))
;l'autosize n'est pas encore au point, faut un refresh
InvalidateRect_(WindowID(), #Null, #True)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
DeleteObject_(hBrush)
EndIf
ben donne moi une police ou ça marche pas ? ....lionel_om a écrit :Oué c'est ca va marcher avec certaines polices, mais pas toutes...
Là tu nous fais ça à l abarbare DoBro !!!