【问题标题】:Can't Hide And Show GUI无法隐藏和显示 GUI
【发布时间】:2022-11-10 01:55:25
【问题描述】:

我正在练习我的 AutoHotkey 技能,似乎遇到了一些问题。

我特别想尝试并学习如何创建一个制作 GUI,但现在我正在尝试制作一种显示和隐藏 GUI 窗口的方法。 我到目前为止的代码是:

; redundant variables for clarity
showConfig := true
hotkeyNew1 := ""
hotkeyNew2 := ""

; prompt for the hotkeys
Gui, New, , Config
Gui, Add, Text, x10 y10, Enter a hotkey for MsgBox1
Gui, Add, Hotkey, x+0 vhotkeyNew1, %vhotkeyNew1%
Gui, Add, Text, x10 y+0, Enter a hotkey for MsgBox2
Gui, Add, Hotkey, x+0 vhotkeyNew2, %vhotkeyNew2%
Gui, Add, Button, x10 y+0 w100 gSendHotkeys, Set Hotkeys
Gui, Show, hide w200 h100 Center, Config ; I assume this initializes the GUI? Either way, it doesn't seem to change anything if I omit it

!+s::
/*
; Note that this was my first attempt, but it yeilded a blank GUI
Gui, Show, % (showConfig ? "" : "hide") . " w200 h100", Config
*/
; This was my second attempt, also yielding a blank GUI
if (showConfig) {
    Gui, Config:Show, w200 h100 Center, Config
} else {
    Gui, Config:Hide
}
showConfig := !showConfig
return


SendHotkeys:
Hotkey, %hotkeyNew1%, hotkey1
Hotkey, %hotkeyNew2%, hotkey2
return

hotkey1:
MsgBox, Hotkey1
return

hotkey2:
MsgBox, Hotkey2
return

#+e:: ExitApp

有没有办法用热键隐藏和取消隐藏 GUI?我似乎无法让它工作。如果有帮助,我正在编写脚本然后编译它。

【问题讨论】:

    标签: user-interface autohotkey


    【解决方案1】:

    你在这里不小心遇到了一个很奇怪的问题。
    这是我之前写过的答案,请参见此处:
    https://stackoverflow.com/a/64750451/3813732

    那应该可以解决您的问题,如果您有任何问题,请告诉我。

    除此之外,我想说你在命名 gui 上调用 ShowHide 的方法会奏效,但实际上你从未命名你的 gui。
    要命名您的 gui,您的第一个 gui 代码行应该是:
    Gui, Config:New, , Config

    此外,您在 gui 命令中重复地重新指定信息,例如 gui 的标题。指定一次就全部存储,无需多次指定。

    【讨论】:

      猜你喜欢
      • 2020-04-19
      • 2023-03-03
      • 2011-01-11
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2011-04-04
      相关资源
      最近更新 更多