Vertically center string gadget

Just starting out? Need help? Post your questions and find answers here.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Vertically center string gadget

Post by coco2 »

Can you vertically center the text in a string gadget?
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: Vertically center string gadget

Post by Bisonte »

here in this post from Shardik are some links : https://www.purebasic.fr/english/viewto ... 51#p537851
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Vertically center string gadget

Post by coco2 »

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
Sergey
User
User
Posts: 60
Joined: Wed Jan 12, 2022 2:41 pm

Re: Vertically center string gadget

Post by Sergey »

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
EndIf
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Vertically center string gadget

Post by coco2 »

Does that work for string gadget? Looks like it is only for text gadget
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Vertically center string gadget

Post by jacdelad »

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
Post Reply