How to set the component property

Members

(constant) Set the component property

Users can directly set the single property of a component instance to update it.

Example
# Suppose there is a button named Button_26 in the workspace.
# 假设工作区中有一个名为Button_26的按钮

    // Check whether the button is enabled, and then toggle the button to switch its state.
    // 检查按钮是否启用,然后切换其状态
    if (Instance.Button_26.enabled) {
        Instance.Button_26.enabled = false; // 禁用按钮
    } else {
        Instance.Button_26.enabled = true; // 启用按钮
    }

    // Set the button text to "AppStudio"
    // 设置按钮文本为“ABB robot”
    Instance.Button_26.text = "AppStudio";

    // Check whether the button is hidden, and then toggle the button to switch its visibility.
    // 检查按钮是否隐藏,然后切换其可见性
    if (Instance.Button_26.hidden) {
        Instance.Button_26.show(); // 如果按钮隐藏,则显示按钮
    } else {
        Instance.Button_26.hide(); // 如果按钮可见,则隐藏按钮
    }

    // Set the button height to 100
    // 设置按钮高度为100
    Instance.Button_26.height = 100;

    // Set the button width to 100
    // 设置按钮宽度为100
    Instance.Button_26.width = 100;

    // Set the font size of the button text to 20
    // 设置按钮文本的字体大小为20
    Instance.Button_26.fontSize = 20;

    // Set the font weight of the button text to bold
    // 设置按钮文本的字体加粗
    Instance.Button_26.fontWeight = 'bold';

    // Reset the font weight of the button text to normal
    // 将按钮文本的字体粗细重置为正常
    Instance.Button_26.fontWeight = 'normal';

    // Set the font style of the button text to italic
    // 设置按钮文本的字体为斜体
    Instance.Button_26.fontStyle = 'italic';

    // Add an underline to the button text
    // 为按钮文本添加下划线
    Instance.Button_26.textDecoration = "underline";

    // Change current background color
    Instance.Button_26.backgroundColor = "rgb(0,0,255)"; // 把背景改为蓝色

    // Add an event listener for the button click event
    // 为按钮点击事件添加事件监听器
    Instance.Button_26.onClick = () => {
        TComponents.Popup_A.message("onClick");
        console.log("onClick"); // 点击按钮时弹窗显示 "onClick"
    };

    // Add an event listener for the pointer down event
    // 为按钮按下事件添加事件监听器
    Instance.Button_26.onPointerDown = () => {
       TComponents.Popup_A.message("onPointerDown");
        console.log("onPointerDown"); // 点击按钮时弹窗显示 "onPointerDown"
    };

    // Add an event listener for the pointer release event
    // 为按钮释放事件添加事件监听器
    Instance.Button_26.onPointerRelease = () => {
       TComponents.Popup_A.message("onPointerRelease");
        console.log("onPointerRelease"); // 点击按钮时弹窗显示 "onPointerRelease"
    };