Dynamic Buttons


The following example shows a dialog in which both the text and image on the button are dynamically derived. In this next example, the text and the image on the 'Save' button are changed when the user clicks on the button. The following script displays a dialog with a button with the text 'Save' on it:

save_text = "Save:$a5_save"
open_text = "Open:$a5_open"
button_text = save_text
result = ui_dlg_box("Bitmap and Text on a Button",<<%dlg%
File: [.64filename];
 <%O={J=LC} {I=:$(:)+1}  {@1,$(:)-1} ; %15,1.5=button_text!save_file>
if a_dlg_button  = "save_file" then
    if button_text = save_text then
        button_text = open_text
        button_text = save_text
    end if
    a_dlg_button = ""
end if

This script produces this dialog:

images/XD_Dynamic image 2.gif

When the user click on the 'Save' button, the button changes to this:

images/XD_Dynamic image 1.gif

Let's analyze the owner-draw string for this button:

O={J=LC} {I=:$(:)+1}  {@1,$(:)-1}
  • {J=LC} 

    The button is left justified horizontally, and center justified vertically

  • {I=:$(:)+1} 

    Display an image on the button. The bitmap is specified by name (because of the colon directive after the equals sign). The name is derived from the input to the owner-draw control. The name is derived starting with the first character after the colon in the input value, through the end of the input value. The input value is specified by the variable 'button_text'. This variable is initially set to "Save:$a5_save". Therefore, the initial bitmap for the button is '$a5_save'.

  • {@1,$(:)-1} 

    Displays text on the button. The text is derived from the input string, starting with the first character, through to the character before the first colon. Initially the input value is 'Save:$a5_save', so the text on the button is 'Save'. By specifying the button text as ' =button_text ', we indicate to Alpha Anywhere that the button's text is derived from the variable 'button_text'.


Desktop applications only.

See Also