Now you have a working sample from resizing also the fonts
Fonts are only resized when the vertical factor exceeds 10 , 20 , 30 .. % from 1 . This can be changed in the increment ( 10 or -10 ) from currentheight
Frank
Code: Select all
FUNCTION MAIN()
***************
LOCAL oWnd , oFont
LOCAL cVar := PAD("TEST ON RESIZE WITH FONT",35)
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, -24
DEFINE WINDOW oWnd
@ 10, 10 GET cVar OF oWnd SIZE 400,24 PIXEL FONT oFont
@ 60, 60 BUTTON "&Close" SIZE 100,24 PIXEL FONT oFont;
ACTION oWnd:End()
ACTIVATE WINDOW oWnd;
ON RESIZE RESIZECONTROLS(nSizeType,nWidth,nHeight,oWnd )
oFont:end()
RETURN NIL
************************************************************************************************************
STATIC FUNCTION RESIZECONTROLS(nSizeType,nWidth,nHeight, oWnd )
***************************************************************
STATIC aCoordinates := {} , FV
STATIC StartWidth , StartHeight
STATIC CurrentHeight
LOCAL i , aHlp[5] , F := Hash()
LOCAL oCtl
LOCAL NewFontH , oFont , cFaceName , lNewFont := .F.
IF EMPTY( aCoordinates )
FOR EACH oCtl IN oWnd:aControls
AADD(aCoordinates , Array(5))
i := Hb_EnumIndex()
aCoordinates[i,1] := oCtl:nTop
aCoordinates[i,2] := oCtl:nLeft
aCoordinates[i,3] := oCtl:nWidth()
aCoordinates[i,4] := oCtl:nHeight()
aCoordinates[i,5] := oCtl:oFont:nHeight
NEXT
StartWidth := oWnd:nWidth()
StartHeight := oWnd:nHeight()
FV := 1
lFont := .F.
CurrentHeight := 0
ENDIF
F["H"] := oWnd:nWidth()/StartWidth // horizontal
F["V"] := oWnd:nHeight()/StartHeight // vertical
IF F["V"] <> FV
IF ABS(ROUND(( F["V"] - 1 )*100 ,2 ) - CurrentHeight) > 10
lNewFont := .T.
IF F["V"] > FV
CurrentHeight += 10
ELSEIF F["V"] < FV
CurrentHeight -= 10
END
ENDIF
ENDIF
FOR EACH oCtl IN oWnd:aControls
i := Hb_EnumIndex()
aHlp[1] := aCoordinates[i,1]*F["V"] // nTop
aHlp[2] := aCoordinates[i,2]*F["H"] // nLeft
aHlp[3] := aCoordinates[i,3]*F["H"] // nWidth
aHlp[4] := aCoordinates[i,4]*F["V"] // nHeight
oCtl:Move( aHlp[1] , aHlp[2] , aHlp[3] , aHlp[4] , .T. )
IF lNewFont
NewFontH := ROUND(aCoordinates[i,5]*F["V"],0)
oFont := oCtl:oFont
cFaceName := oFont:cFaceName
oFont:end()
DEFINE FONT oFont NAME cFaceName SIZE 0, -NewFontH
oCtl:SetFont(ofont)
oCtl:refresh()
END
NEXT
FV := F["V"]
RETURN