KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Adjust font size on a form in run time
PRODUCT: 4D | VERSION: 14 R4 | PLATFORM: Mac & Win
Published On: April 20, 2015

In 4D v14R4 and newer, the command FORM GET OBJECTS is updated to specify a page of a form to extract the set of objects. The method below can focus (e.g. Form current page) on a particular page of the form to adjust the font size of visible objects at run time:

// ----------------------------------------------------------------------
// Name: FORM_ADJUST_FONT_SIZE
// Description: Locates all the objects in the current form and adjust
// the Font size.
// Parameters:
// $1 (LONGINT) - 1 - Increase font size, 0 - Decrease font size
// ----------------------------------------------------------------------
C_LONGINT($1;$inc;$i;$temp_font_size)
ARRAY TEXT(objectsArray;0)
ARRAY POINTER(variablesArray;0)
ARRAY LONGINT(pagesArray;0)

If (Count parameters>=1)
   $inc:=$1
   FORM GET OBJECTS(objectsArray;variablesArray;pagesArray;Form current page)

   For ($i;1;Size of array(objectsArray))
      $temp_font_size:=OBJECT GET FONT SIZE(*;objectsArray{$i})
      If ($inc=1) // Increase the size of the font
         $temp_font_size:=$temp_font_size+1
      Else // Decrease the size of the font
         $temp_font_size:=$temp_font_size-1
      End if
      OBJECT SET FONT SIZE (*;objectsArray{$i};$temp_font_size)
   End for
End if


An example would be to use the Invisible button and assign a shortcut key:



To increase the font size, insert in the Invisible Button object method code:

FORM_ADJUST_FONT_SIZE(1) // Increase font size


When pressing the shortcut key, text in the objects would increase as shown below with a Variable, Button, and Check Box:



Decreasing the font size can be done by assigning a shortcut to another Invisible button and placing the following object method code:

FORM_ADJUST_FONT_SIZE(0) // Decrease font size


Pressing this newly assigned shortcut key will decrease the font size as shown below:




See Also: