How To | Disable a button using Lua scripting

Learn how to use Lua scripting to make a button disappear from a page or application.

Updated at January 2nd, 2024

Procedure


The Component.New() method allows you to gain control over any object in a component, as long as that component has a unique name (i.e., is a named component).  This is very useful if you want to make changes on the fly without compiling.

  1. Drag a scripting component into the design.
  2. Drag a Custom Controls component into the design and give it a name. (Select the component and type a name - in this example, "Test".)
  3. Set the custom control to Momentary and drag it into the design.
  4. Open the script editor. Copy this code snippet into your script:
    • Component.New("Test").momentary_1.IsDisabled = true
  5. Click the yellow tab to save, and then press F6 to emulate the design. You will see the button gray out and become inactive.
  6. Now, change to this code:
    • Component.New("Test").momentary_1.IsInvisible = true
  7. Save and press F6 to emulate. You should see the button go invisible, which disables it as well.