我目前正在尝试学习使用 AutoHotkey 编写脚本。我正在尝试创建一个脚本,当选中复选框并按下确认按钮时,它会生成一个 MsgBox,其结果由复选框更改。例如,如果选中“您是绿色”复选框,我会尝试弹出一个 MsgBox 告诉您您是绿色的。如果同时选中两个复选框,它会告诉您您既是绿色又是蓝色。我在寻找示例和解决方案时遇到了麻烦,如果您能提供一些帮助或推动正确的方向,我将不胜感激。谢谢。
Gui, Add, Checkbox, vIsBlue, Are you Blue?
Gui, Add, Checkbox, vIsGreen, Are you Green?
Gui, Add, Button, Default gConfirm, Confirm
Gui, Show
Return
Confirm:
{
Gui, Submit
if vIsBlue = 1
MsgBox, You're Blue,, Blue
if vIsBoth = 1
MsgBox, You're Blue and Green,, Blue and Green
if vIsGreen = 1
MsgBox, You're Green,, Green
Return
}
答案1
您已经非常接近了!当您在 Gui 命令中声明变量时,即vIsBlue
,随后在子程序中调用的变量名称不需要在v
其前面加上。我还通过重新排序和添加语句修复了您的If
语句逻辑。Else If
Gui, Add, Checkbox, vIsBlue, Are you Blue?
Gui, Add, Checkbox, vIsGreen, Are you Green?
Gui, Add, Button, Default gConfirm, Confirm
Gui, Show
Return
Confirm:
Gui, Submit
if (IsBlue = 1) and (IsGreen = 1)
MsgBox, You're Blue and Green,,, Blue and Green
else if IsBlue = 1
MsgBox, You're Blue,,, Blue
else if IsGreen = 1
MsgBox, You're Green,,, Green
Return