Vertically center string gadget
Vertically center string gadget
Can you vertically center the text in a string gadget?
Re: Vertically center string gadget
here in this post from Shardik are some links : https://www.purebasic.fr/english/viewto ... 51#p537851
Re: Vertically center string gadget
Thanks I got it working. Here it is for future people:
Code: Select all
Procedure SetGadgetTextVCenter(gadNum.i)
Protected.i hdc = GetDC_(GadgetID(gadNum))
Protected.RECT eRect
Protected.SIZE textXY
Protected.s GadgetText = GetGadgetText(gadNum)
GetTextExtentPoint32_(hdc, GadgetText, Len(GadgetText), @textXY)
ReleaseDC_(GadgetID(gadNum), hdc)
GetClientRect_(GadgetID(gadNum), eRect)
eRect\top = (eRect\Bottom - textXY\cy) / 2
SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect)
EndProcedure
#CENTERED_HORIZ = 1
Define.i Event
LoadFont(0, "Arial", 11)
OpenWindow(0, 0, 0, 500, 400, "Vertical Center", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 10, 10, 80, 30, "24", #CENTERED_HORIZ | #PB_String_Numeric | #ES_MULTILINE)
SetGadgetFont(0, FontID(0))
SetGadgetTextVCenter(0)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
Re: Vertically center string gadget
On Windows you may use #SS_CENTERIMAGE
Code: Select all
If OpenWindow(0, 0, 0, 270, 110, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 250, 40, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)
TextGadget(1, 10, 60, 250, 40, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border | #SS_CENTERIMAGE)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIfRe: Vertically center string gadget
Does that work for string gadget? Looks like it is only for text gadget
Re: Vertically center string gadget
Yeah, #SS_... is for Static Controls only. (=TextGadget)
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD


