Sign in to follow this  
Followers 0
dabus

"Resize" font to fit gui...

6 posts in this topic

Hi @ all,

I wrote a simple app that's used to upgrade an application that does not have a self-update-functionality. I build a simple gui that loads the changelog and puts it into an edit-box. There's also a label and a button to close the gui. It looks ok (I know, I could use some themes to add some beauty) if people use the 96-dpi standard, but the gui is too small if they use 120 dpi. I just added a simple solution that reads the dpi and multiplies the size of gui. It looks like this:

#include <GuiConstants.au3>

Global $DPIMultiplicator=RegRead('HKCU\Control Panel\Desktop\WindowMetrics', 'AppliedDPI')/96

Func FixGui($a)
    Return Round($a*$DPIMultiplicator,0)
EndFunc 

$Dir='D:\Transfer'
$Gui=GuiCreate("Xxxxx-Xxxx Update", FixGui(400), FixGui(250),-1, -1, -1 , $WS_EX_TOPMOST )
$Icon1 = GuiCtrlCreateIcon(@SystemDir & "\shell32.dll", 22, 10, 10, 40, 40)
$Label = GuiCtrlCreateLabel('fsdfsdöfljadkfjlöasdjfldfadf654sda4sd654as6d546ss4d654, ' & @CR & _ 
    'andother dfsdfjsdhfsdhfhla646464654654654654.', 70, 10, FixGui(320), FixGui(40))
$Edit1 = GuiCtrlCreateEdit(FileRead($Dir&'\Update\Changelog.txt'), 10, FixGui(65), FixGui(380), FixGui(135))
$Button1 = GUICtrlCreateButton('OK', FixGui(125), FixGui(210), FixGui(150), 25)
GUICtrlSetState($Button1,$GUI_DEFBUTTON)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button1
        ExitLoop
    EndSelect
WEnd
GUIDelete($Gui)

Sometimes I would like to keep guis small. SOmetimes all the layout of the gui would be messed up if I use FixGui().

To devide the fontsize in the same way as shown above will not get you a fontsize that would fit into fixed label/edit-borders. Obvious, eh ? :rolleyes:

Question: Is it possible to calculate the font-size in a way that would be fitting this purpose?

Thx in advance.

Share this post


Link to post
Share on other sites



Hi @ all,

I wrote a simple app that's used to upgrade an application that does not have a self-update-functionality. I build a simple gui that loads the changelog and puts it into an edit-box. There's also a label and a button to close the gui. It looks ok (I know, I could use some themes to add some beauty) if people use the 96-dpi standard, but the gui is too small if they use 120 dpi. I just added a simple solution that reads the dpi and multiplies the size of gui. It looks like this:

#include <GuiConstants.au3>

Global $DPIMultiplicator=RegRead('HKCU\Control Panel\Desktop\WindowMetrics', 'AppliedDPI')/96

Func FixGui($a)
    Return Round($a*$DPIMultiplicator,0)
EndFunc 

$Dir='D:\Transfer'
$Gui=GuiCreate("Xxxxx-Xxxx Update", FixGui(400), FixGui(250),-1, -1, -1 , $WS_EX_TOPMOST )
$Icon1 = GuiCtrlCreateIcon(@SystemDir & "\shell32.dll", 22, 10, 10, 40, 40)
$Label = GuiCtrlCreateLabel('fsdfsdöfljadkfjlöasdjfldfadf654sda4sd654as6d546ss4d654, ' & @CR & _ 
    'andother dfsdfjsdhfsdhfhla646464654654654654.', 70, 10, FixGui(320), FixGui(40))
$Edit1 = GuiCtrlCreateEdit(FileRead($Dir&'\Update\Changelog.txt'), 10, FixGui(65), FixGui(380), FixGui(135))
$Button1 = GUICtrlCreateButton('OK', FixGui(125), FixGui(210), FixGui(150), 25)
GUICtrlSetState($Button1,$GUI_DEFBUTTON)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button1
        ExitLoop
    EndSelect
WEnd
GUIDelete($Gui)

Sometimes I would like to keep guis small. SOmetimes all the layout of the gui would be messed up if I use FixGui().

To devide the fontsize in the same way as shown above will not get you a fontsize that would fit into fixed label/edit-borders. Obvious, eh ? :rolleyes:

Question: Is it possible to calculate the font-size in a way that would be fitting this purpose?

Thx in advance.

You could use GuiCtrlSetFont, and choose a stroked font that has lots of size options like arial say. You can then set either the standard font size or the one used for 120dpi

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Yes, I know I could play around and see if things fit. But I would like to know if I can calculate that value.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yes, I know I could play around and see if things fit. But I would like to know if I can calculate that value.

I think that to calculate the size you just need to say

guictrlsetfont($id,$fontsize.....

where fontsize is

$fontsize = Int($normalfontsize * 96/dpisetting)

If the font size is not available, like for arial it goes 36 to 48 to 72, then you might need a table to find the best size. Otherwise the font will probably be set to the next size up.

In my simple view of the world, font size is the height in pixels for fonts on a screen. Try setting a font size to your dpi setting and put a ruler against the character { which uses all the vertical space and I bet it's 1 inch, or rather I bet it's close because the setting is not exact for some monitors.

One way to look at it is that the 120 dpi is not to change the font size but to keep it the same because the screen has more dots per inch. Therefore, instead of changing the font you really aught to be changing everything else, which is what you were doing with FixGui and I think that's the best way, but painful.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Tanks for your answer.

I tried your suggestion but it didn't work - before I posted the first message. ;D

Maybe I made a mistake and someone can proof me wrong. I even added a messagebox to see if things went wrong, but it said that the fontsize would be 6.4 in 120 dpi and 8 in 96 dpi. In the helpfile it's said that you could use that format. I even tried GuiSetFont and GuiCtrlSetFont but now way...

Maybe I'll have time to test things later.

Share this post


Link to post
Share on other sites

Tanks for your answer.

I tried your suggestion but it didn't work - before I posted the first message. ;D

Maybe I made a mistake and someone can proof me wrong. I even added a messagebox to see if things went wrong, but it said that the fontsize would be 6.4 in 120 dpi and 8 in 96 dpi. In the helpfile it's said that you could use that format. I even tried GuiSetFont and GuiCtrlSetFont but now way...

Maybe I'll have time to test things later.

#include <GUIConstants.au3>

$title = "font sizing takes any value"
$main = GUICreate($title,140,600,0,0)
$cb = GUICtrlCreateCombo("",120,10)
$font="Ariel";Comic Sans MS"
$fontsize = 41.7
$starty = 5
While $fontsize > 2
    $l = GUICtrlCreateLabel($fontsize,5,$starty,200,$fontsize +10)
    GUICtrlSetFont(-1,$fontsize,400,0,$font) 
    $starty += 12 + $fontsize
    $fontsize -= 2.6
    
WEnd
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE 
    WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0