问题
许多应用程序需要提示用户进行输入或选择,然后根据该输入进行操作。 这个食谱创造了一个无模式(即非模态)带有选择的对话框。 当用户点击好的按钮关闭窗口,它将用户输入存储到变量中,然后执行所需的任何工作。
解决方案
这新窗户()函数将创建一个窗口,您可以使用它来提示用户输入。 在新窗口中,您可以使用输入选择器显示框收集用户的选择。
然后你将使用设置函数或设置脚本上的选项按钮盒将显示框中的值存储到 JSL 变量中。
Button Box 中脚本的最后一部分在用户关闭窗口后执行所需的工作。
win = New Window( "Set the Value",
H List Box( Text Box( "Set this value" ), num_edit_box1 = Number Edit Box( 42 ) ),
check_box_1 = Check Box( "On" ),
combo_box1 = Combo Box( {"Choice 1", "Choice 2", "Choice 3"} ),
list_box1 = List Box( {"Choice 3", "Choice 4", "Choice 5"} ),
H List Box(
Button Box( "OK",
//store results in jsl variables
num_input = num_edit_box1 << get;
check_box_input = check_box_1 << get;
combo_box_input = combo_box1 << get selected;
list_box_input = list_box1 << get selected;
//close the window
//wait until you've unloaded the input boxes before you closing
//or else they'll be gone
win << close window;
//now do whatever work you want with the inputs
Show( num_input, check_box_input, combo_box_input, list_box_input );
),
//a cancel button that closes the window and doesn't store store the results
Button Box( "Cancel", win << close window )
)
);
讨论
无模式对话框比模式对话框有点棘手,因为在新窗户()将在对话框关闭之前执行。 这就是为什么您必须将要完成的“工作”放在按钮框脚本中。
也可以看看
从无模式对话框中检索值