問題
許多應用程序需要提示用戶進行輸入或選擇,然後根據該輸入進行操作。 這個食譜創造了一個無模式(即非模態)帶有選擇的對話框。 當用戶點擊好的按鈕關閉窗口,它將用戶輸入存儲到變量中,然後執行所需的任何工作。
解決方案
這新窗戶()函數將創建一個窗口,您可以使用它來提示用戶輸入。 在新窗口中,您可以使用輸入選擇器顯示框收集用戶的選擇。
然後你將使用設置函數或設置腳本上的選項按鈕盒將顯示框中的值存儲到 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 )
)
);
討論
無模式對話框比模式對話框有點棘手,因為在新窗戶()將在對話框關閉之前執行。 這就是為什麼您必須將要完成的“工作”放在按鈕框腳本中。
也可以看看
從無模式對話框中檢索值