Page 1 of 1

Change font size of gadgets

Posted: Mon Jun 18, 2018 10:53 am
by Lebostein
How I can change the font size only? I can reset the default gadget font for all gadgets. But I do not want to change the default font of the operating system (I don't know which font is used), only the size...

Re: Change font size of gadgets

Posted: Mon Jun 18, 2018 12:54 pm
by RSBasic

Code: Select all

EnableExplicit

Define NONCLIENTMETRICS.NONCLIENTMETRICS
NONCLIENTMETRICS\cbSize = SizeOf(NONCLIENTMETRICS)
SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS, 0, NONCLIENTMETRICS, 0)

LoadFont(1, PeekS(@NONCLIENTMETRICS\lfCaptionFont\lfFaceName[0]), 20)

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetGadgetFont(#PB_Default, FontID(1))
  
  ButtonGadget(1, 10, 10, 100, 30, "Button")
  TextGadget(2, 10, 50, 100, 30, "Hello")
  CheckBoxGadget(3, 10, 100, 100, 30, "Checkbox")
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
I hope lfCaptionFont is the right one.

Re: Change font size of gadgets

Posted: Mon Jun 18, 2018 3:58 pm
by chi
Windows only

Code: Select all

LoadFont(0, "MS Shell Dlg", 8)
SetGadgetFont(#PB_Default, FontID(0))

OpenWindow(0, 0, 0, 320, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

ButtonGadget(0, 10, 10, 100, 30, "Button")
TextGadget(1, 10, 50, 100, 30, "Hello")
CheckBoxGadget(2, 10, 100, 100, 30, "Checkbox")

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

Code: Select all

GetObject_(GetStockObject_(#DEFAULT_GUI_FONT), SizeOf(LOGFONT), @lf.LOGFONT)
Debug PeekS(@lf\lfFaceName[0])

Re: Change font size of gadgets

Posted: Mon Jun 18, 2018 5:09 pm
by RASHAD

Code: Select all

FID = GetGadgetFont(#PB_Default)
fnt.LOGFONT    
GetObject_(FID,SizeOf(fnt),@fnt)
FName$ =  PeekS(@fnt\lfFaceName[0])
LoadFont(0,Fname$,18)
SetGadgetFont(#PB_Default,FontID(0))

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10, 10, 100, 30, "Button")
  TextGadget(2, 10, 50, 100, 30, "Hello")
  CheckBoxGadget(3, 10, 100, 140, 30, "Checkbox") 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
           
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf

Re: Change font size of gadgets

Posted: Thu Jul 19, 2018 4:41 pm
by Lebostein
Thanks, it seems there is no solution with PB possible, only for Windows with API functions...

Re: Change font size of gadgets

Posted: Fri May 30, 2025 3:53 pm
by Mesa
8 years later, a pb solution:

Code: Select all

; FID = GetGadgetFont(#PB_Default)
; fnt.LOGFONT    
; GetObject_(FID,SizeOf(fnt),@fnt)
; FName$ =  PeekS(@fnt\lfFaceName[0]):Debug FName$


LoadFont(0,"",18)
SetGadgetFont(#PB_Default,FontID(0))

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10, 10, 100, 30, "Button")
  TextGadget(2, 10, 50, 100, 30, "Hello")
  CheckBoxGadget(3, 10, 100, 140, 30, "Checkbox") 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf

Re: Change font size of gadgets

Posted: Sun Jun 01, 2025 12:39 am
by Olli
@mesa

Hello, and thank you for this tip.

Code: Select all

LoadFont(0,"",18)
Is this cross platform ?

Re: Change font size of gadgets

Posted: Sun Jun 01, 2025 11:40 am
by mk-soft
Yes with PB >= v6.xx

Re: Change font size of gadgets

Posted: Mon Jun 02, 2025 10:39 am
by Axolotl
Cool.
Is this documented anywhere?
Couldn't find anything in the help.

Re: Change font size of gadgets

Posted: Mon Jun 02, 2025 12:36 pm
by Mindphazer
Olli wrote: Sun Jun 01, 2025 12:39 am @mesa

Hello, and thank you for this tip.

Code: Select all

LoadFont(0,"",18)
Is this cross platform ?
Works on MacOS at least

Re: Change font size of gadgets

Posted: Mon Jun 02, 2025 12:40 pm
by Mindphazer
Mesa wrote: Fri May 30, 2025 3:53 pm

Code: Select all

LoadFont(0,"",18)
I guess "" is considered as an unexisting font, so the system font is used.
Try

Code: Select all

 LoadFont(0,"***",18)
it has the same results