It is currently Fri Aug 23, 2019 2:28 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject:
PostPosted: Mon Oct 02, 2006 10:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 6:51 pm
Posts: 778
Location: NC, USA
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:
#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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye