FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to determine string HEIGHT and WIDTH
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
How to determine string HEIGHT and WIDTH
Posted: Sat Mar 10, 2012 01:36 PM

Hi,
Please how can i determine string HEIGHT and WIDTH if i need to SAY it with some font on dialog.
I need that to can calculate DIALOG size where i want to SAY that string using some font too.
For example:

cString := "iiiiiiiiii"
or other solution
cString := "WWWWWWWWWW"

DEFINE DIALOG oDlg SIZE ?,?
@ 0,0 SAY cString FONT oFont

I want DIALOG to have size just to SAY string on it.

Best regards,

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to determine string HEIGHT and WIDTH
Posted: Sat Mar 10, 2012 03:15 PM
Try it this way:

Code (fw): Select all Collapse
   local oDlg, oSay, cText := "hello world"

   DEFINE DIALOG oDlg

   @ 0, 0 SAY oSay PROMPT cText OF oDlg

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT oDlg:SetSize( oSay:nWidth, oSay:nHeight )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: How to determine string HEIGHT and WIDTH
Posted: Sat Mar 10, 2012 05:00 PM
Antonio,

tested, but doesn't work.
The Result :



My Test and Function returns a adjusted Dialog ( a little bit more complicated ) :



Some space between Dlg-top / Text-top and Dlg-bottom / Text-bottom.
Can be adjusted to Dlg-top = Text-top and Dlg-bottom = Text-bottom

A little Test-tool, selecting any Font and changing Size and Style :
( I added only a small Space for g, j, p, q and y on Bottom )
You can change the top, left, right and bottom-space.
A INI-file is used, to save and restore a Font.



For the calculated Dialog-height, some Adjustments are needed.

For the Textheight :

oFont1 := TFont():New("Arial",,-nFSize,.F.,.T. ,,,,.F. )
nTxtHeight := INT( Abs( oFont1:nHeight ) ) + 22
( nFSize is selected, 22 = Height of Dialog-title )

For the calculated Textwidth and Dialog-size I used :

Code (fw): Select all Collapse
// -- calculated Text-width ----------------

FUNCTION TEXT_W( oSay, nTxtHeight ) 

hDC := oSay:GetDC()
IF oFont1:lItalic = .F. // Italic
    nTxtWidth :=  INT( GettextWidth( hDC, ALLTRIM(cText), oFont1:hFont, ) ) + 6
ELSE
    nTxtWidth :=  INT( GettextWidth( hDC, ALLTRIM(cText), oFont1:hFont, ) ) + 8
ENDIF
oSay:ReleaseDC()
oSay:nWidth := nTxtWidth
// 15 = added Space on Bottom 
// ---------------------------------
oDlg2:Move( nPosT, nPosL, nTxtWidth, nTxtHeight + 15, .T. )
oSay:Refresh()

RETURN ( NIL )


Best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion