Thanks to all for all this precious codes
The code of FLUID BYTE is exactely what i want, because it see the size of the font
But he have again a little problem
I can't add a line, in the string gadget, when i do RETURN
And i also can't add line, when the numbers of characters, is upper at the size of the line
The line, can just to be add, with the code not with the keyboard :roll:
Code: Select all
Procedure StringGadgetVCenter(GadgetID)
hwndEdit = GadgetID(GadgetID)
LineCount = SendMessage_(hwndEdit,#EM_GETLINECOUNT, 0, 0)
hdc = GetDC_(hwndEdit)
SelectObject_(hdc,GetGadgetFont(0))
GetTextExtentPoint32_(hdc,"ABC",3,fsz.SIZE)
ReleaseDC_(hwndEdit,hdc)
GetClientRect_(hwndEdit,eRect.RECT)
eRect\top = (GadgetHeight(GadgetID) - fsz\cy * LineCount) / 2
eRect\bottom = eRect\top + (fsz\cy * LineCount) + 4
If eRect\bottom < GadgetHeight(GadgetID)
SendMessage_(hwndEdit,#EM_SETRECT,0,eRect)
EndIf
EndProcedure
Text$ = "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget"
OpenWindow(0,0,0,300,200,"Edit Control VCenter",#WS_SYSMENU|#WS_CAPTION | 1)
StringGadget(0,10,10,280,180,Text$,#ES_MULTILINE|#ES_CENTER )
SetGadgetFont(0,LoadFont(0,"Arial",12))
StringGadgetVCenter(0)
LinesNum = SendMessage_(GadgetID(0), #EM_GETLINECOUNT,0,0)
Repeat
EventID = WaitWindowEvent()
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change And LinesNum <> SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
LinesNum = SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
StringGadgetVCenter(0)
EndIf
EndSelect
Until EventID = #PB_Event_CloseWindow