1. Edinson Nongrados
  2. PowerBuilder
  3. Tuesday, 5 October 2021 06:36 AM UTC

Hi, the image is a curstomized Usercontrol PB 19, there're 2 elements a Picture and a StaticText, i need to align the text on the bottom as now. 

But as i using staticText, i need to set the height and the position of the control for that reason sometimes i this result.

The sentence is not on the bottom of the UserObject, I'm using a Picture and not a PictureButton, because with the picture control you can set a Blob directly from the BD and it's not necesary put it on local, a PC.

I need Picture control.

René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 5 October 2021 11:02 AM UTC
  2. PowerBuilder
  3. # 1

Hi Edinson,

In PFC platform service (pfc_n_cst_platformunicode) you can find the function of_GetTextSize. It uses Windows API to get the size (width and height) of a text. If you know the height you can set the correct position for the text.

AFAIK the function doesn't handle CRLF right. If your text contains CRLF you have to calculate the height and width for each line. Add the heights and use Max function over all lines to get the width.

HTH,

René

 

Comment
  1. René Ullrich
  2. Wednesday, 6 October 2021 06:49 AM UTC
Hi Edinson,

You can download the PFC here: https://github.com/OpenSourcePFCLibraries

It should be very simple to extract the function.
  1. Helpful
  1. Edinson Nongrados
  2. Friday, 8 October 2021 11:07 AM UTC
IDK what happen cause the function is returning only the Height but the Width is 0.
  1. Helpful
  1. Edinson Nongrados
  2. Monday, 11 October 2021 13:52 PM UTC
How can I calculate the height and width for each line ? How can i use the DrawTextExW WinAPI function has a formatting option (DT_CALCRECT = 1024) ? please
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 5 October 2021 13:44 PM UTC
  2. PowerBuilder
  3. # 2

Hi Edison;

  For this type of presentation, I often use either a DataWindow or Picture button, as follows:

If the text is externally driven - it will observe the ~r~n tildes.

Food for thought

Regards ... Chris

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 11 October 2021 16:05 PM UTC
  2. PowerBuilder
  3. # 3

Here is a working example script from a command button's Clicked event that calls the PFC's of_GetTextSize function of the Platform service. The command button resides in a window, not on a tab page. The single line of text is taken from a Single-Line Edit control in the window named sle_textsize.

Boolean lb_bold, lb_ital, lb_undr
Integer li_rc, li_w, li_h, li_fontsize
String  ls_fontface, ls_text
Window  lw_parent
n_cst_platform lnv_platform

ls_text = sle_textsize.Text

lw_parent = Parent   // Obtain reference to parent window.
ls_fontface = sle_textsize.Facename
li_fontsize = Abs(sle_textsize.Textsize)

If sle_textsize.Weight = 400 Then
   lb_bold = False
Else
   lb_bold = True
End If

lb_ital = sle_textsize.Italic
lb_undr = sle_textsize.Underline

f_SetPlatform(lnv_platform,True)
li_rc = lnv_platform.of_GetTextSize(lw_parent,ls_text, &
            ls_fontface,li_fontsize,lb_bold,lb_ital, &
            lb_undr,li_h,li_w)
f_SetPlatform(lnv_platform,False)

MessageBox('of_GetTextSize Results', &
   'RC = ' + String(li_rc) + &
   ', Height = ' + String(li_h) + &
   ', Width = ' + String(li_w))

A limitation of the of_GetTextSize function (and the Windows API function that it calls) is that it can only calculate the size of a single line of text. Please note the underlying Windows API function this PFC function calls returns the height and width in PIXELS, not PowerBuilderUnits. If you need PBU's, you'll need to use the PowerScript PixelsToUnits conversion function to perform the translation.

If you're experiencing difficulties getting this PFC Platform service's function to work, then frankly I'm doubtful you will be able to get an example of the Windows API DrawTextEx function to work, as it is a more complex API function and there is not a PFC-supplied interface to utilize it... you would have to call the API function directly from PB.

I encourage you to consider Chris' suggestion and if possible, avail yourself of the functionality of the PB Picture Button control.

Comment
  1. Edinson Nongrados
  2. Wednesday, 13 October 2021 07:16 AM UTC
the function of_GetTextSize works for me but i've noticed that the function only returned the height but the width is 0, which is impossible.

idk if this happened to you.
  1. Helpful
  1. John Fauss
  2. Thursday, 14 October 2021 04:13 AM UTC
I would not have posted code that you could try if it didn't work. Did you try running the example code? This code returns both the width and height of the text in pixels.



Be sure to take the absolute value of the font textsize, as I did in the example code. PB font point sizes are negative values (I don't know why).
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.