GuiSize question to color a Button in Msgbox Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

GuiSize question to color a Button in Msgbox

Post by eagerahk » 05 Dec 2022, 09:30

Based on Garry's post viewtopic.php?t=29591#p139568, I slightly modified the code to

Code: Select all

Gui,Color,Yellow
Gui, Font, s20, Times New Roman
Gui,Add,Text,      x25  y20   w300    h30   BackgroundTrans  ,Line 1
Gui,Add,Text,      x25  y50   w300    h30   BackgroundTrans  ,Line 2
Gui,Add,Text,      x25  y80   w300    h30   BackgroundTrans  ,Line 3

Gui, Font, s26
Gui,Add,Progress,  x90 y125 w60 h50  Disabled BackgroundLime vP1
Gui,Add,Text,       xp yp   w60 h50   border BackgroundTrans Center gRTN1,OK

Gui, Show, x300 y300 w500 h200 ,test
return
guiescape:
guiclose:
exitapp

GuiSize:
GuiControlGet, Progress1, focus
GuiControlGet, Text4, pos, OK
GuiControl, Move, Progress1, % "x" (A_GuiWidth)//2
GuiControl, Move, Text1, % "x" (A_GuiWidth)//2
return

RTN1:
  msgbox My name is %A_GuiControl%
  exitapp
The two GuiControl statements obviously did not work as expected. Could anyone give any advice? Thanks

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

Re: GuiSize question to color a Button in Msgbox

Post by mikeyww » 05 Dec 2022, 09:34

AHK commands use literal strings, so you can use % for variables, as you have already shown in the subsequent parameter.

Code: Select all

GuiControl, Move, %Progress1%, % "x" A_GuiWidth / 2

eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: GuiSize question to color a Button in Msgbox

Post by eagerahk » 05 Dec 2022, 09:57

Thanks, mikeyww.
I retry %Progress1%, and the GuiSize still not work as expected.

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

Re: GuiSize question to color a Button in Msgbox

Post by mikeyww » 05 Dec 2022, 10:02

It "worked" when I tested it.

Your problem statement appears to be
did not work
Instead, you could answer the following two questions.

1. What actually happened when you ran the script?
2. What should happen instead?

And:

3. Post a revised script in a reply below.

eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: GuiSize question to color a Button in Msgbox

Post by eagerahk » 05 Dec 2022, 10:27

Thanks mikeyww again, here is the revised code

Code: Select all

Gui,Color,Yellow
Gui, Font, s20, Times New Roman
Gui,Add,Text,      x25  y20   w300    h30   BackgroundTrans  ,Line 1
Gui,Add,Text,      x25  y50   w300    h30   BackgroundTrans  ,Line 2
Gui,Add,Text,      x25  y80   w300    h30   BackgroundTrans  ,Line 3

Gui, Font, s26
Gui,Add,Progress,  x90 y125 w60 h50  Disabled BackgroundLime vP1
Gui,Add,Text,       xp yp   w60 h50   border BackgroundTrans Center gRTN1,OK

Gui, Show, x300 y300 w500 h200 ,test
return
guiescape:
guiclose:
exitapp

GuiSize:
GuiControlGet, Progress1, focus
GuiControlGet, Text4, pos, OK
GuiControl, Move, %Progress1%, % "x" A_GuiWidth//2
GuiControl, Move, %Text4%, % "x" A_GuiWidth//2
return

RTN1:
  msgbox My name is %A_GuiControl%
  exitapp
The new test result moves text1 to the right, instead of text4, and the Button OK is not located at x500 // 2 (i.e. x250). Thanks

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

Re: GuiSize question to color a Button in Msgbox  Topic is solved

Post by mikeyww » 05 Dec 2022, 10:33

Debugging is simple, because you can display the value of your variables such as Progress1. When you displayed the value, what did you find?

Code: Select all

GuiSize:
cx := A_GuiWidth / 2
GuiControl, Move, P1, x%cx%
GuiControl, Move, OK, x%cx%
Return
Explained: Focus
Retrieves the control identifier (ClassNN) for the control that currently has keyboard focus.
You can add code that accounts for the width of the control itself.

Code: Select all

GuiSize:
GuiControlGet, p1, Pos, P1
GuiControlGet, ok, Pos, OK
GuiControl, Move, P1, % "x" (A_GuiWidth - p1W) / 2
GuiControl, Move, OK, % "x" (A_GuiWidth - okW) / 2
Return

Code: Select all

GuiSize:
center("P1")
center("OK")
Return

center(control) {
 GuiControlGet, pos, Pos, %control%
 GuiControl, Move, %control%, % "x" (A_GuiWidth - posW) / 2
}

eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: GuiSize question to color a Button in Msgbox

Post by eagerahk » 05 Dec 2022, 11:13

Thanks a lot, mikeyww. It now fully works.

Post Reply

Return to “Ask for Help (v1)”