KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Shaking a form
PRODUCT: 4D | VERSION: 15.x | PLATFORM: Mac & Win
Published On: November 8, 2016

A way to grab the attention of a user is to shake the 4D form. The following method will shake the form by controlling the number of pixels to shift from left to right and interations of the shifts:

// --------------------------------------------------------------------------------
// Name: SHAKE_FORM_WINDOW
// Description: Method will shake the form window by shifting the left and right.
// Window Rect coordinates.
// Input:
// $1 (LONGINT) - Window to shift
// $2 (LONGINT) - Pixels to shift the form from left to right
// $3 (LONGINT) - Number of times to shift left to right
// --------------------------------------------------------------------------------
C_LONGINT($1;$window)
C_LONGINT($2;$pixelShift)
C_LONGINT($3;$iterationOfShifts)
C_LONGINT($i;$leftO;$topO;$rightO;$bottomO)
C_LONGINT($leftW;$rightW)

If (Count parameters=3)
   $window:=$1
   $pixelShift:=$2
   $iternationOfShifts:=$3

   GET WINDOW RECT($leftO;$topO;$rightO;$bottomO;$window)

   $leftW:=$leftO
   $topW:=$topO
   $rightW:=$rightO
   $bottomW:=$bottomO

   For ($i;1;$iternationOfShifts) // Shift form left to right
      SET WINDOW RECT($leftW-$pixelShift;$topO;$rightW-$pixelShift;$bottomO;$window)
      DELAY PROCESS(Current process;3)
      SET WINDOW RECT($leftW+$pixelShift;$topO;$rightW+$pixelShift;$bottomO;$window)
      DELAY PROCESS(Current process;3)
   End For

   SET WINDOW RECT($leftO;$topO;$rightO;$bottomO;$window) // Original position

End If


Here is an example of shaking a form window at 20 pixels for 3 iterations:



// Code used in the object method of the button
SHAKE_FORM_WINDOW (Frontmost window;20;3)