Change default control font in UI

I started building the UI for my app and had placed some controls when I decided to change the font for the controls in the edit/options/default control font. All the controls I added to the UI after this point had the new font but all the controls I added before the font change still have the old font. I know I can just delete and add the controls again but was interested if anyone had any ideas on why this happens or any way to quickly fix this issue?

Never mind…I found the location in the inspector settings…

I use this method (in a module), so I can change all at once.

Public Sub setWinFonts(mywin as window)
  for i as integer = 0 to mywin.ControlCount-1
    if mywin.Control(i) isa Label then
      Label(mywin.Control(i)).TextFont = "System"
      Label(mywin.Control(i)).TextSize = 10
    end if
    if mywin.Control(i) isa GroupBox then
      GroupBox(mywin.Control(i)).TextFont = "System"
      GroupBox(mywin.Control(i)).TextSize = 11
      GroupBox(mywin.Control(i)).Bold = true
    end if
    if mywin.Control(i) isa PushButton then
      Pushbutton(mywin.Control(i)).Height = 26
      Pushbutton(mywin.Control(i)).TextFont = "System"
      Pushbutton(mywin.Control(i)).TextSize = 10
    end if
    if mywin.Control(i) isa PopupMenu then
      PopupMenu(mywin.Control(i)).TextFont = "System"
      PopupMenu(mywin.Control(i)).TextSize = 10
    end if
    if mywin.Control(i) isa CheckBox then
      CheckBox(mywin.Control(i)).TextFont = "System"
      CheckBox(mywin.Control(i)).TextSize = 10
    end if
  next
End Sub

Axel, may I suggest you use a tmp variable to access “mywin.Control(i)” only once? It’ll do wonders to your code size and performance, especially if you follow such a rule everywhere in your code :wink:

Like this, after the “for …” line:

dim theCtrl as RectControl = mywin.Control(i)

And then use just “theCtrl” in its place in all further lines. Makes it more readable as well.

you’re right,

I started only with label and then thought it can also be used for other controls.
So I then used the Guttenberg-Method (copy & paste)

Steve Guttenberg?

Karl-Theodor zu Guttenberg

sorry, lame attempt at humor, obviously not appreciated :slight_smile:

and I’ll be honest… Guttenberg the printer, and Guttenberg the actor are the only two I know

https://en.wikipedia.org/wiki/Steve_Guttenberg

He got the nickname ‘copy & paste’ when it was discovered that he cheated in his doctoral dissertation.

Dave, K-T zu G was a high ranking politician who was caught having plagiarized his master(?) thesis, and losing his job over it. (https://en.wikipedia.org/wiki/Karl-Theodor_zu_Guttenberg#Plagiarism_scandal_and_resignation)

(Axel beat me to it)

the better version

Public Sub setWinFonts(mywin as window)
  dim theCtrl as Control 
  for i as integer = 0 to mywin.ControlCount-1
    theCtrl = mywin.Control(i)
    if theCtrl isa Label then
      Label(theCtrl).TextFont = "System"
      Label(theCtrl).TextSize = 10
    end if
    if theCtrl isa GroupBox then
      GroupBox(theCtrl).TextFont = "System"
      GroupBox(theCtrl).TextSize = 11
      GroupBox(theCtrl).Bold = true
    end if
    if theCtrl isa PushButton then
      PushButton(theCtrl).Height = 26
      PushButton(theCtrl).TextFont = "System"
      PushButton(theCtrl).TextSize = 10
    end if
    if theCtrl isa PopupMenu then
      PopupMenu(theCtrl).TextFont = "System"
      PopupMenu(theCtrl).TextSize = 10
    end if
    if theCtrl isa CheckBox then
      CheckBox(theCtrl).TextFont = "System"
      CheckBox(theCtrl).TextSize = 10
    end if
  next
End Sub