Change font size of gadgets

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Change font size of gadgets

Post 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...
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Change font size of gadgets

Post 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.
Image
Image
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Change font size of gadgets

Post 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])
Et cetera is my worst enemy
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4941
Joined: Sun Apr 12, 2009 6:27 am

Re: Change font size of gadgets

Post 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
Egypt my love
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Re: Change font size of gadgets

Post by Lebostein »

Thanks, it seems there is no solution with PB possible, only for Windows with API functions...
Mesa
Enthusiast
Enthusiast
Posts: 433
Joined: Fri Feb 24, 2012 10:19 am

Re: Change font size of gadgets

Post 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
Olli
Addict
Addict
Posts: 1194
Joined: Wed May 27, 2020 12:26 pm

Re: Change font size of gadgets

Post by Olli »

@mesa

Hello, and thank you for this tip.

Code: Select all

LoadFont(0,"",18)
Is this cross platform ?
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Change font size of gadgets

Post by mk-soft »

Yes with PB >= v6.xx
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Axolotl
Enthusiast
Enthusiast
Posts: 797
Joined: Wed Dec 31, 2008 3:36 pm

Re: Change font size of gadgets

Post by Axolotl »

Cool.
Is this documented anywhere?
Couldn't find anything in the help.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Change font size of gadgets

Post 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
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Change font size of gadgets

Post 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
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply