未选中复选框时如何禁用输入框

问题描述

这是对话框中复选框和输入框的脚本。我想知道如何在未选中复选框的情况下禁用该条目。

class TestUI : UIFrame {
    number true,false
    TestUI(object self) {
        true = 1; 
        false = 0;
        result("[TestUI] constructed\n")
    };
    
    ~TestUI(object self)    {
        result("[TestUI] destructed\n")
    };
    
    void CreateDialog(object self)  {
        TagGroup dialog = DLGCreateDialog("Test")
        TagGroup cb = DLGCreateCheckBox("IsCheck",false).DLGAnchor("West")
        TagGroup parameter
        TagGroup entry = DLGCreateRealField("Parameter : ",parameter,5,8,1)
        dialog.DLGAddElement(cb)
        dialog.DLGAddElement(entry)
        
        self.init(dialog).display("TestUI")
        
    };
};

{
    alloc(TestUI).CreateDialog()
}

enter image description here

提前致谢。

解决方法

查看手册后,我找到了解决方案。 可以通过添加函数并在复选框更改时使用“SetElementIsEnabled”启用/禁用该功能来启用/禁用该条目。

最初,该条目被“DLGEnabled”禁用。

脚本如下:

class TestUI : UIFrame {
    number true,false
    TagGroup para1,para2

    TestUI(object self) {
        true = 1; 
        false = 0;
        result("[TestUI] constructed\n")
    };
    
    ~TestUI(object self)    {
        result("[TestUI] destructed\n")
    };
    
    void SelectionAct(object self,TagGroup tgItem) {
        // To change the status while the checkbox is changing.
        self.SetElementIsEnabled("BtnGroup",tgItem.DLGGetValue())
    };
    
    void BtnResponse(object self)   {
        result("Parameter 1 : "+para1.DLGGetValue()+"\n")
        result("Parameter 2 : "+para2.DLGGetValue()+"\n")
    };
    
    void CreateDialog(object self)  {
        
        // the box is not selected when initiation 
        // To enable/disable the entry by building "SelectionAct" function
        TagGroup cb = DLGCreateCheckbox("IsCheck",false,"SelectionAct").DLGAnchor("West")
        
        TagGroup entry1 = DLGCreateRealField("Parameter 1 : ",para1,5,3)
        TagGroup entry2 = DLGCreateRealField("Parameter 2 : ",para2,6,3)
        
        // print the value
        TagGroup Btn = DLGCreatePushButton("Print","BtnResponse").DLGFill("X").DLGIdentifier("btn")
        
        // Group the entries and button,we can change their status with ease.
        TagGroup EntryGroup = DLGGroupItems(entry1,entry2).DLGTableLayout(2,1,0).DLGIdentifier("entries")
        TagGroup BtnGroup = DLGGroupItems(EntryGroup,Btn).DLGTableLayout(1,2,0).DLGIdentifier("BtnGroup")
        
        // disable the entries and btn when initiation
        DLGEnabled(BtnGroup,false)
        
        // create dialog
        TagGroup dialog = DLGCreateDialog("Test")
        dialog.DLGAddElement(cb)
        dialog.DLGAddElement(BtnGroup)
        
        self.init(dialog).Display("TestUI")
    };
};

{
    alloc(TestUI).CreateDialog()
}

结果: enter image description here