Problem with GUI Control

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Problem with GUI Control

09 Jan 2018, 16:38

I've got a script in process where I want to change the text in a GUI.
https://www.dropbox.com/s/noqf9sgr8llnm ... e.JPG?dl=0

i want to be able to select a file and have the 'n/a' be replaced by the filename. must be having a brain f**t because i can't seem to get it working. can someone show me what i'm doing wrong?

Code: Select all

Link = n/a

Gui, Add, Button, gLink, File_Link
Gui, Add, Text,, %Link%

Gui, Show, w150 h220, QuickAdd ; was 190

GuiControl,, %Link%, %Link%

return

Link:
msgbox, %Link%
repl .= "%20"
FileSelectFile, Link
msgbox, %Link%
IfInString, Link, %A_Space%
	{
	StringReplace, newlink, Link, %A_Space%, %repl%, All
	}
	else
	{
	msgbox, %newlink%
	newlink = %Link%
	}
	msgbox, %Link%
	
return

exitapp
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Problem with GUI Control

09 Jan 2018, 23:57

try entering the path to the file, i have a hard time with GUI too i might not be any help at all, i have found just generally, when we call on scripts to retrieve something they'll need the path

just my thoughts, ive never attempted such things myself

example:

C:\Users\User A\Pictures\Saved Pictures

Code: Select all

:*:aa::
run, calc.exe
return
oh i think maybe i miss read your comment, you want to select a file and have that show in the gui, you might need that clipboard stuff, im not sure just highlighting something is enough, you should try the clipboard scripts, then you can highlight, copy, and you have it saved to clipboard for pasting in the "n/a" field.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Problem with GUI Control

10 Jan 2018, 01:56

replace GuiControl,, %Link%, %Link%
with this GuiControl,, Link, %Link%
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Problem with GUI Control

10 Jan 2018, 10:36

thanks wolf_II, but doesn't seem to do anything. n/a stays n/a in the dialog box.
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Problem with GUI Control

10 Jan 2018, 10:52

As is,

Code: Select all

GuiControl,, %Link%, %Link%
is executed only once when the script is started. So how would the control's contents be changed?
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Problem with GUI Control

10 Jan 2018, 11:11

my bad, this seems to work as I need. one thing though: when the n/a field is changed to the %Link% contents, the length of the field doesn't automatically change with the length of the variable. How can I make the length change as the length of the variable data changes? I can always put in a width specification into the gui, add, text line, and make it always longer than needs to be. but can this length be dependent on the variable data length? I know I can use 'guicontrol, move,... and put in a width #, but i'd prefer to have that width change with the width of the variable.

Code: Select all

Link = n/a

Gui, Add, Button, gFile_Link, File_Link
Gui, Add, Text, w100 vLink, % Link

Gui, Show, w250 h220, QuickAdd

return

File_Link:
msgbox, %Link%
FileSelectFile, Link
msgbox, %Link%
GuiControl,, Link, %Link%
msgbox, %Link%
return

exitapp
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Problem with GUI Control

10 Jan 2018, 11:43

Hi sttrebo,

You can for example use StrLen function in order to set the width of the control depending on the length of the input.

Code: Select all

Gui, Add, Button, Section gsubroutine, &File_Link
Gui, Add, Edit, ys+1 vtextControl +ReadOnly, n/a ; 'vtextControl' associates the variable 'textControl' with the control
Gui, Show, AutoSize, QuickAdd
return ; end of the auto-execute part of the script

subroutine: ;  named subroutine
FileSelectFile, selectedFile ; give relevant name to your variables
if not (ErrorLevel) { ;  if the user did not dismissed the dialog without selecting a file...
	link := StrReplace(selectedFile, A_Space, "%20") ; use functions instead; StrReplace returns the result of the replacement process(using expressions strings are enclosed in quotes)
	GuiControl,, textControl, % link
	GuiControl, Move, textControl, % "w" . StrLen(link)*5 ; set the width of the control depending on the length of the input (using expressions strings are enclosed in quotes)
	Gui, Show, AutoSize Center ; resize an center the GUI
}
return ; end of the subroutine

Hope this helps.
my scripts
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: Problem with GUI Control

10 Jan 2018, 11:51

very nice, thanks for the help all. i really appreciate all of the comments and assistance.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 387 guests