How to make default Button using a ButtonName saved in ini file? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rosto
Posts: 30
Joined: 06 Jan 2016, 08:54

How to make default Button using a ButtonName saved in ini file?

Post by Rosto » 15 May 2022, 16:17

I'm using an ini file to store the last clicked button in my gui (A_GuiControl) with the aim of making this the default button.

The variable name in the ini file is: FocusLast

My gui:

Code: Select all

Gui, Add, Edit, x10 y10 vSearch w335, 
Gui, Add, Text, x10 w70 y+20, Search:
Gui, Add, Button, x+5 gSearchGoogle vSearchGoogle, Google
Gui, Add, Button, x+5 gSearchBing vSearchBing, Bing
Gui, Add, Button, x+5 gSearchDuckduck vSearchDuckduck, Duckduck
Gui, Add, Button, x+5 gSearchYouTube vSearchYouTube, YouTube
Gui, Add, Button, x+5 gSearchFB vSearchFB, FB
Gui, Show
Let's say if FocusLast = SearchBing
How can I add "Default" after vSearchBing?

User avatar
mikeyww
Posts: 26604
Joined: 09 Sep 2014, 18:38

Re: How to make default Button using a ButtonName saved in ini file?  Topic is solved

Post by mikeyww » 15 May 2022, 18:31

Code: Select all

For each, button in ["Google", "Bing", "Duckduck", "YouTube", "FB"] {
 default := FocusLast = "Search" button ? "Default" : ""
 Gui, Add, Button, x+5 gSearch%button% vSearch%button% %default%, %button%
}

Rosto
Posts: 30
Joined: 06 Jan 2016, 08:54

Re: How to make default Button using a ButtonName saved in ini file?

Post by Rosto » 16 May 2022, 03:01

Thank you very much for your answer and your solution. Great!

I want to ask you one more thing. I want to add even more buttons to the GUI with a text block in front of it eg:

Code: Select all

Gui, Add, Text, x10 w70, Software:
Gui, Add, Button, x+5 gSoftwareSoftp, Softp
Gui, Add, Button, x+5 gSoftwareSnapf, Snapf
Gui, Add, Button, x+5 gSoftwareTechsup, Techsup
Gui, Add, Button, x+5 gSoftwarePlaystore, Playstore
There will be a problem with all text lines and eventually if I want to adapt a single buttonwidth isn't it?

Rosto
Posts: 30
Joined: 06 Jan 2016, 08:54

Re: How to make default Button using a ButtonName saved in ini file?

Post by Rosto » 16 May 2022, 03:13

And I found two more problems:
1) I think I will have buttons with the same name like this:

{search item}
search [Google] [Bing] [Duckduckgo]
images [Google] [Bing] [Duckduckgo]

2) How can I put the text "search", "images" before a line with buttons?
(please see my initial question)

Thanks again.

User avatar
mikeyww
Posts: 26604
Joined: 09 Sep 2014, 18:38

Re: How to make default Button using a ButtonName saved in ini file?

Post by mikeyww » 16 May 2022, 06:12

You can do it the same way that you have already demonstrated. If needed, you can specify the width of each button.

Explained: Positioning and sizing of controls

Rosto
Posts: 30
Joined: 06 Jan 2016, 08:54

Re: How to make default Button using a ButtonName saved in ini file?

Post by Rosto » 22 Dec 2022, 05:15

mikeyww wrote:
15 May 2022, 18:31

Code: Select all

For each, button in ["Google", "Bing", "Duckduck", "YouTube", "FB"] {
 default := FocusLast = "Search" button ? "Default" : ""
 Gui, Add, Button, x+5 gSearch%button% vSearch%button% %default%, %button%
}
above script you've been created has been converted with V2Converter to:

Code: Select all

SearchM.Add("Text", "x10 w70 y+20", "Search:")
For each, button in ["Google", "Bing", "Duckduck", "YouTube", "FB"] {
 default := FocusLast = "Search" button ? "Default" : ""
 ogcButtonSearch := SearchM.Add("Button", "x+5 " . button . " vSearch" . button . " " . default, button)
 ogcButtonSearch.OnEvent("Click", Search.Bind("Normal"))
}
This gives now this error:

Code: Select all

Warning: This variable appears to never be assigned a value.

Specifically: local Search

▶	ogcButtonSearch.OnEvent("Click", Search.Bind("Normal"))
I've tried to declare the variable Search (global Search) but that doesn't work.
Do you know what's going wrong?

User avatar
mikeyww
Posts: 26604
Joined: 09 Sep 2014, 18:38

Re: How to make default Button using a ButtonName saved in ini file?

Post by mikeyww » 22 Dec 2022, 09:58

You could post your new script in the v2 forum.

Rosto
Posts: 30
Joined: 06 Jan 2016, 08:54

Re: How to make default Button using a ButtonName saved in ini file?

Post by Rosto » 23 Dec 2022, 07:29

mikeyww wrote:
22 Dec 2022, 09:58
You could post your new script in the v2 forum.
viewtopic.php?f=82&t=111892

Post Reply

Return to “Ask for Help (v1)”