KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Dynamically manage a Picture display format on a 4D form
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: December 6, 2013

A nice fieature developers can provide users is the ability to change the display of a Picture field or variable. This Tech Tip shows how to manage a Popup menu that can dynamically change the display of a 4D Picture field or variable on a 4D form. As written it does not manage images on a form background. However, the code could easily be adopted to do it.

The images below is of a Popup that shows the Picture display formats to be managed in a Picture field or variable.



The Popup menu is set to reflect the current display mode of the picture under the On Load event. The code in the On Data Change changes the display format after the user makes a new choice in the menu.

If (True)
    If (False)
      Begin SQL
      /*
        Name: PictureDisplayFormat
        Path: [projectForm]PictureDisplayFormat

        Purpose: Capture and/or change Picture display format
      */
      End SQL
    End if
    C_TEXT($MethodName_T)
    $MethodName_T:=Current method name
    //=========================== Declare Variables ===========================
    //method_parameters_declarations
    //--------------------------------------------------------------------------------
    //method_wide_constants_declarations
    C_LONGINT(Mode_L)
    //--------------------------------------------------------------------------------
    //local_variable_declarations
    C_LONGINT($Ndx;$SOA;$RIS;$FormEvt_L)
    C_POINTER($Self_P)
    C_TEXT($Format_T)
End if
//=========================== Initialize and Setup ===========================
$FormEvt_L:=Form event
$Self_P:=Self

//=========================== Method Actions ===========================
Case of
    : ($FormEvt_L=On Load)
    Mode_L:=Character code(OBJECT Get format(*;"MyPicture_G"))

    Case of
      : (Mode_L=Scaled to Fit)
        $Self_P->:=1

      : (Mode_L=Scaled to fit prop centered)
        $Self_P->:=2

      : (Mode_L=Scaled to fit proportional)
        $Self_P->:=3

      : (Mode_L=Truncated Centered)
        $Self_P->:=4

      : (Mode_L=Truncated non Centered)
        $Self_P->:=5
    End case
    //
    //--------------------------------------------------------------------------------
    : ($FormEvt_L=On Data Change)
    Case of
      : ($Self_P->=1)
        Mode_L:=Scaled to Fit

      : ($Self_P->=2)
        Mode_L:=Scaled to fit prop centered

      : ($Self_P->=3)
        Mode_L:=Scaled to fit proportional

      : ($Self_P->=4)
        Mode_L:=Truncated Centered

      : ($Self_P->=5)
        Mode_L:=Truncated non Centered
    End case

    OBJECT SET FORMAT(*;"MyPicture_G";Char(Mode_L))
    REDRAW(MyPicture_G)
    //
    //--------------------------------------------------------------------------------
End case