How to change GUI button text (v2) without destroying/recreating new GUI? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 26
Joined: 20 Jul 2016, 09:28

How to change GUI button text (v2) without destroying/recreating new GUI?

23 Apr 2024, 04:35

When I click the button called "OLD", it changes to "NEW", but to achieve that, it first need to destroy the GUI, then create it agan. just an ugly behavior.

Code: Select all

#Requires AutoHotkey v2.0

global btn_name := "OLD"

x::
{
    MyGui := Gui(, "Mouse")
    MyGui.SetFont("s10") 
    MyGui.Add("Button", "w220 h30", btn_name).OnEvent("Click", ButtonClick)

    MyGui.Show("w250 h100")

    ButtonClick(*) {
        global btn_name := "NEW"  
        MyGui.Destroy()
        send "{x}"
    }
}
Draken
Posts: 53
Joined: 08 Dec 2022, 01:19

Re: How to change GUI button text (v2) without destroying/recreating new GUI?  Topic is solved

23 Apr 2024, 05:09

Code: Select all

#Requires AutoHotkey v2.0

btn_name := "OLD"

x::{
    global
    MyGui := Gui(, "Mouse")
    MyGui.SetFont("s10") 
    MyGui.Add("Button", "w220 h30 vbtn", btn_name).OnEvent("Click", ButtonClick)

    MyGui.Show("w250 h100")

    ButtonClick(*) {
        Mygui["btn"].Text := "NEW"
    }
}
just me
Posts: 9505
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to change GUI button text (v2) without destroying/recreating new GUI?

23 Apr 2024, 06:34

The first parameter of an event function is the Guicontrol object (similar to A_GuiControl in v1). So you can use:

Code: Select all

    ButtonClick(BtnObj, *) {
        BtnObj.Text := "NEW"
    }
to change the button's caption.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww, Tvlao and 41 guests