Disable or enable a component

更新时间:
复制 MD 格式

You can disable or enable a component by setting its Enabled property. This topic uses the 'more' menu button as an example to show how to disable a component.

  • Demonstration

    • Disabled button (grayed out): On the toolbar, components such as the Start button, the format buttons (B, I, U, and S), the Font drop-down list, and the Font Size drop-down list are disabled.

    • The View Switch button (the three-line icon) in the upper-left corner of the toolbar is enabled.

  • Syntax

    expression.CommandBars(CommandBarId).Enabled

    expression: The application object for the document.

  • Example

    async function example() {
      await instance.ready();
      const app = instance.Application;
      // Get the more menu object.
      const moreMenus = await app.CommandBars('MoreMenus');
      // Disable the more menu.
      moreMenus.Enabled = false;
      // Get the menu's enabled status.
      const enabled = await moreMenus.Enabled;
      console.log(enabled);
    }