How to modify the text in the GUI?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Giresharu
Posts: 17
Joined: 16 Apr 2024, 07:21
Contact:

How to modify the text in the GUI?

22 May 2024, 15:16

I tried using Gui.Destroy() and then creating a new Gui, but even if I destroy it and create a new window immediately, then show it right away, there is often a brief flicker.
Is there any API that allows modifying the text without destroying the window?

Here's my code of gui:

Code: Select all

Shift:: {
    static myGui := ""
    if (myGui != "") {
        myGui.Destroy()
    }
    myGui := Gui("-SysMenu +ToolWindow +AlwaysOnTop -Caption -DPIScale +E0x20")
    myGui.Add("Text",,"Test")
    myGui.Show("w250 h100")
}
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: How to modify the text in the GUI?

22 May 2024, 15:24

Don't create the Gui in the hotkey. Create it once, and then just show it (Shift key in this example) or change the text (Ctrl key in this example):

Code: Select all

#Requires AutoHotkey v2.0

myGui := Gui("-SysMenu +ToolWindow +AlwaysOnTop -Caption -DPIScale +E0x20")
myGui.Add("Text", "vMyText", "Test")

Shift::myGui.Show("w250 h100")

Ctrl::myGui["MyText"].Text := "New"
Giresharu
Posts: 17
Joined: 16 Apr 2024, 07:21
Contact:

Re: How to modify the text in the GUI?

22 May 2024, 15:55

@boiler
There seems to be a problem with writing this way, the initial string of myGui.Add determines the range of the text, if the initial text is very short, such as an empty string, and the rest of the code remains the same, Pressing ctrl will only show a "N".

Code: Select all

#Requires AutoHotkey v2.0

myGui := Gui("-SysMenu +ToolWindow +AlwaysOnTop -Caption -DPIScale +E0x20")
myGui.Add("Text", "vMyText", "")

Shift::myGui.Show("w250 h100")

Ctrl::myGui["MyText"].Text := "New"
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: How to modify the text in the GUI?

22 May 2024, 17:49

You just need to set the width of the field because without a set width, the width of the control is set by the initial text it contains.

Code: Select all

myGui.Add("Text", "vMyText w200", "")

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Google [Bot], Hansielein and 69 guests