I needed a way to control the placement of the text in a borderless stringgadget, specifically I wanted to align the text at the bottom of the gadget rather than at the top.
A forum search turned up this topic and another similar one with example code by Sparkie.
So, using srod's hint above, this is what I came up with, thanks to some of Sparkie's code. Sparkie's works with multiple lines in the stringgadget, but I only needed handling for one line of text in each stringgadget.
I did not get it working with textgadgets, but someone else may have a go at it.
Note: The stringgadget must be multiline for this to work.
Code: Select all
#VP_CENTER = 0
#VP_BOTTOM = 1
Procedure SetGadgetTextVPosition(gadNum, vPosition.l=1)
; Get width and height of text on one line
hdc = GetDC_(GadgetID(gadNum))
GetTextExtentPoint32_(hdc, "AQbcj10", 7, @textXY.SIZE)
ReleaseDC_(GadgetID(gadNum), hdc)
;--> Get and reset rect coordinates for StringGadget
eRect.RECT
GetClientRect_(GadgetID(gadNum), eRect)
Select vPosition
Case #VP_CENTER
eRect\top = (eRect\Bottom - textXY\cy) / 2
Case #VP_BOTTOM
eRect\top = eRect\bottom - textXY\cy
EndSelect
SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect)
EndProcedure
; Example code
#Cou_Font_N12 = 1
LoadFont(#Cou_Font_N12 ,"DGCourier", 12)
SetGadgetFont(#PB_Default, FontID(#Cou_Font_N12))
If OpenWindow(0, 0, 0, 270, 160, "Vertical Postitioned Text", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
StringGadget(1, 10, 10, 60, 40, "AbjQ", #PB_String_ReadOnly | #PB_Text_Border|#ES_MULTILINE)
SetGadgetColor(1,#PB_Gadget_BackColor,RGB(255,255,0))
SetGadgetColor(1,#PB_Gadget_FrontColor,RGB(0,0,255))
SetGadgetTextVPosition(1,#VP_CENTER)
StringGadget(2, 90, 10, 60, 40, "ABCjqhi", #PB_String_BorderLess |#ES_MULTILINE) ;<<<!!!
SetGadgetColor(2,#PB_Gadget_BackColor,RGB(255,255,0))
SetGadgetColor(2,#PB_Gadget_FrontColor,RGB(0,0,255))
SetGadgetTextVPosition(2)
SetActiveGadget(1)
While WindowEvent():Wend
Delay(5000)
SetGadgetText(1,"gojo")
While WindowEvent():Wend
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf