dg0421 Posted September 2, 2008 Share Posted September 2, 2008 How can I automatically resize the fonts that are within a control? In my program the controls all scale automatically when the GUI is resized by the user, but like the font to be scaled as well. Link to comment Share on other sites More sharing options...
simbo Posted September 2, 2008 Share Posted September 2, 2008 I'm sure someone will have a better solution, but I use the $BS_BITMAP style and set a BMP image using GUICtrlSetImage.It's rather time consuming, but seems to work. AFAIK Windows just doesn't do scalable fonts on controls.MattHow can I automatically resize the fonts that are within a control? In my program the controls all scale automatically when the GUI is resized by the user, but like the font to be scaled as well. Link to comment Share on other sites More sharing options...
rasim Posted September 3, 2008 Share Posted September 3, 2008 dg0421Welcome! Show your code, please. Link to comment Share on other sites More sharing options...
dg0421 Posted September 3, 2008 Author Share Posted September 3, 2008 The attached code will allow a GUI to be resized by the user and the label control also resizes but the font doesn't. I would like the font to auto-resize with the control. #include <GUIConstants.au3> $StatusView = GUICreate("Window Title",600,400,-1,-1,$WS_SIZEBOX+$WS_SYSMENU,$WS_EX_TOPMOST) GUISetFont (14,400,-1,"Arial") $CtrlStatus = GUICtrlCreateLabel("This is a test",0,0,600,150, $SS_Center) GUICtrlSetResizing ($CtrlStatus,$GUI_DOCKAUTO) GUICtrlSetColor($CtrlStatus,0x000000) GUICtrlSetFont($CtrlStatus,10,400,-1,"Arial Black") GUICtrlSetState($CtrlStatus,$GUI_Show) GUISetState (@SW_SHOW,$StatusView) While 1 $Event = GUIGetMsg() If $Event = $GUI_EVENT_CLOSE Then ExitLoop EndIf WEndTest.au3 Link to comment Share on other sites More sharing options...
rasim Posted September 3, 2008 Share Posted September 3, 2008 dg0421Try this:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> $StatusView = GUICreate("Window Title",600,400,-1,-1, BitOR($WS_SIZEBOX, $WS_SYSMENU), $WS_EX_TOPMOST) GUISetFont(14, 400, Default, "Arial") $CtrlStatus = GUICtrlCreateLabel("This is a test", 0, 0, 600, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetFont(-1, 10, 400, Default, "Arial Black") GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetState(@SW_SHOW, $StatusView) While 1 $Event = GUIGetMsg() If $Event = $GUI_EVENT_CLOSE Then ExitLoop EndIf WEnd Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) Local $aPos = ControlGetPos($StatusView, "", $CtrlStatus) Local $iSize = $aPos[3] - 4 If $iSize > 10 Then $iSize = 10 ElseIf $iSize <= 0 Then $iSize = 1 EndIf GUICtrlSetFont($CtrlStatus, $iSize, 400, Default, "Arial Black") Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
dg0421 Posted September 3, 2008 Author Share Posted September 3, 2008 dg0421 Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> $StatusView = GUICreate("Window Title",600,400,-1,-1, BitOR($WS_SIZEBOX, $WS_SYSMENU), $WS_EX_TOPMOST) GUISetFont(14, 400, Default, "Arial") $CtrlStatus = GUICtrlCreateLabel("This is a test", 0, 0, 600, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetFont(-1, 10, 400, Default, "Arial Black") GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetState(@SW_SHOW, $StatusView) While 1 $Event = GUIGetMsg() If $Event = $GUI_EVENT_CLOSE Then ExitLoop EndIf WEnd Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) Local $aPos = ControlGetPos($StatusView, "", $CtrlStatus) Local $iSize = $aPos[3] - 4 If $iSize > 10 Then $iSize = 10 ElseIf $iSize <= 0 Then $iSize = 1 EndIf GUICtrlSetFont($CtrlStatus, $iSize, 400, Default, "Arial Black") Return $GUI_RUNDEFMSG EndFunc That's pretty cool! The font does automatically scale down but when I make the GUI larger (by dragging right corner) the font doesn't get larger. I looked at the GUIRegister function in the help guide but it wasn't immediatly apparent to me how this works. Is there a way to get it to scale both larger and smaller? Link to comment Share on other sites More sharing options...
dg0421 Posted September 3, 2008 Author Share Posted September 3, 2008 RASIM -- OK .... Thanks a bunch ..... U ROCK!!! I slightly changed your routine and got it to work for my application. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now