GUI > Position of edit field Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Naitsirk
Posts: 40
Joined: 15 Feb 2022, 03:50

GUI > Position of edit field

Post by Naitsirk » 28 Sep 2022, 05:20

I am trying to make a quite simple GUI to gather some information.

My skills in this are very basic, so I've relied much on help in this forum, guides and trial and error.

In this script in gui 2, I just cant seem to be able to place the

Code: Select all

Gui, 2:Add, Edit, vPR1
next to "Fra lufthavn". It's always placed underneath.

Code: Select all

^2::
Sleep, 250
Gui, Destroy
Gui, Add, Text,, Booking type:
Gui, Add, DropDownList, ym vPm, Pakkerejse|Flybillet|
Gui, Add, Button, default, OK  
Gui, Show,, Travel booking
return  

GuiClose:
ButtonOK:
Gui, Submit  

Sleep, 250

If (Pm = "Pakkerejse")
{
Sleep, 250
Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text,, Fra lufthavn
Gui, 2:Add, Edit, vPR1
Gui, 2:Add, Button, default, OK  
Gui, 2:Add, Text, ym, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Show,, Package deal
return  

2GuiClose:
2ButtonOK:
Gui, 2:Submit  
Return
}
I really hope there is an easy way around this without have to put in coordinates.

Thanks in advance :)

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GUI > Position of edit field

Post by BoBo » 28 Sep 2022, 05:48

…around this without have to put in coordinates.
I'd guess that AHK's "autopositioning" in 99 out of 100 cases isn’t the preferable way to go.
So yes, at least IMHO you have to set a few GUIControl coordinates.
And no, it’s not that difficult: https://www.autohotkey.com/docs/commands/Gui.htm#PosSize

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

Re: GUI > Position of edit field

Post by mikeyww » 28 Sep 2022, 06:24

Code: Select all

Gui,   Add, Text        ,      ym+2                     , Booking type:
Gui,   Add, DropDownList,      ym   w155    vPm         , Pakkerejse|Flybillet
Gui,   Add, Button      , xm        w230    Default     , OK
Gui, 2:Add, Text        ,                               , Afrejsedato
Gui, 2:Add, MonthCal    ,                   vMyCalendar
Gui, 2:Add, Text        ,      ym           Section     , Hjemrejsedato
Gui, 2:Add, MonthCal    ,                   vMyCalendar1
Gui, 2:Add, Text        , xm   y+10                     , Fra lufthavn:
Gui, 2:Add, Edit        , x+m  yp-3 w137    vPR1
Gui, 2:Add, Button      , xs   yp   w207 hp Default     , OK

^2::Gui, Show,, Travel booking

ButtonOK:
Gui, Submit
If (Pm = "Pakkerejse")
 Gui, 2:Show,, Package deal
Return

2ButtonOK:
Gui, 2:Submit
Return

Naitsirk
Posts: 40
Joined: 15 Feb 2022, 03:50

Re: GUI > Position of edit field

Post by Naitsirk » 28 Sep 2022, 08:24

mikeyww wrote:
28 Sep 2022, 06:24

Code: Select all

Gui,   Add, Text        ,      ym+2                     , Booking type:
Gui,   Add, DropDownList,      ym   w155    vPm         , Pakkerejse|Flybillet
Gui,   Add, Button      , xm        w230    Default     , OK
Gui, 2:Add, Text        ,                               , Afrejsedato
Gui, 2:Add, MonthCal    ,                   vMyCalendar
Gui, 2:Add, Text        ,      ym           Section     , Hjemrejsedato
Gui, 2:Add, MonthCal    ,                   vMyCalendar1
Gui, 2:Add, Text        , xm   y+10                     , Fra lufthavn:
Gui, 2:Add, Edit        , x+m  yp-3 w137    vPR1
Gui, 2:Add, Button      , xs   yp   w207 hp Default     , OK

^2::Gui, Show,, Travel booking

ButtonOK:
Gui, Submit
If (Pm = "Pakkerejse")
 Gui, 2:Show,, Package deal
Return

2ButtonOK:
Gui, 2:Submit
Return
Thanks for your input.

So using your code, this did it:

Code: Select all

Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text, ym Section, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Add, Text, xm y+10, Fra lufthavn:
Gui, 2:Add, Edit, x+m yp-3 w137 vPR1
Gui, 2:Add, Button, default, OK  
Gui, 2:Show,, Package deal
But my issue with writing the coordinates is basically, that I just don't understand it. I've read the guide in this like a 100 times, and I just don't understand it..

So I am again at a complete loss on what to write, if I wanted to add a new text field under "Fra lufthavn", a dropdown under that and so forth... Hmm maybe I should give up.

But if there is an easy way for my to learn it, I would be so thankful.

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: GUI > Position of edit field

Post by garry » 28 Sep 2022, 08:27

@mikeyww works fine , here I added complicated always x y w h

@Naitsirk here I used always x y w h ( with percent calculation , depending screensize , Example x:=(wa*50)/xx means x-position from GUI should be in the middle of screen
or just can add , as example : Gui,add,button ,x100 y200 w100 h30 gA1 ,OK ;- here gA1 is the label A1 , the x and y-position is inside the GUI
( a danish movie for children , Olsenbanden 1968 - ( german geoblocked ) > https://mediathekviewweb.de/#query=olsenband )

Code: Select all

Gui,1:default
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100

Gui,1: -DPIScale
color=D4D0C8 
Gui,1:Color,Black,%color%
Gui,1:font,s12 cBlack,Lucida Console

x:=(wa*1)/xx,y:=(ha*1)/xx
Gui,Add, Text        , x%x%  y%y%        , Booking type:

x:=(wa*1)/xx,y:=(ha*3)/xx,w:=(wa*15)/xx,h:=(ha*15)/xx
Gui,Add, DropDownList, x%x%  y%y%  w%w% h%h% vPM     , Pakkerejse|Flybillet

x:=(wa*17)/xx,y:=(ha*3)/xx,w:=(wa*3)/xx,h:=(ha*2.4)/xx
Gui,Add, Button      , x%x% y%y%  w%w% h%h% gA1, OK

x:=(wa*10)/xx,y:=(ha*10)/xx,w:=(wa*25)/xx,h:=(ha*10)/xx
Gui,Show,x%x% y%y% w%w% h%h% ,Travel booking
GuiControl,1: Choose,PM,1
return
;------------
Guiclose:
Exitapp
;------------
A1:
Gui, Submit,nohide
If (Pm = "Pakkerejse")
 gosub,2ndgui
Return
;--------------
2ndGUI:
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
Gui,2: -DPIScale
color=D4D0C8 
Gui,2:Color,Black,%color%
Gui,2:font,s12 cYellow,Lucida Console
;--
x:=(wa*1 )/xx,y:=(ha*1)/xx
Gui, 2:Add, Text        ,x%x%  y%y%                       , Afrejsedato

x:=(wa*1 )/xx,y:=(ha*3)/xx,w:=(wa*25)/xx,h:=(ha*25)/xx
Gui, 2:Add, MonthCal    ,x%x% y%y%  w%w% h%h%   vStartCal

x:=(wa*28)/xx,y:=(ha*1)/xx
Gui, 2:Add, Text        ,x%x% y%y%                       , Hjemrejsedato

x:=(wa*28)/xx,y:=(ha*3)/xx,w:=(wa*25)/xx,h:=(ha*25)/xx
Gui, 2:Add, MonthCal    ,x%x% y%y%  w%w% h%h%   vEndCal

x:=(wa*1 )/xx,y:=(ha*30)/xx
Gui, 2:Add, Text        ,x%x%  y%y%                       , Fra lufthavn:

x:=(wa*8 )/xx,y:=(ha*30)/xx,w:=(wa*10)/xx,h:=(ha*2.5)/xx
Gui, 2:Add, Edit        ,x%x% y%y%  w%w% h%h% cBlack    vPR1 , Københavns Lufthavn

x:=(wa*20)/xx,y:=(ha*30)/xx,w:=(wa*4)/xx,h:=(ha*2.5)/xx
Gui, 2:Add, Button      ,x%x% y%y%  w%w% h%h%  gA2   , OK

x:=(wa*10)/xx,y:=(ha*23)/xx,w:=(wa*55)/xx,h:=(ha*45)/xx
Gui, 2:Show,x%x% y%y%  w%w% h%h% , Package deal
return
;------------
2GuiClose:
Gui,2:destroy
return
;exitapp
;------------

A2:
Gui, 2:Submit,nohide
msgbox,START=`n%startcal%`n`nEND=`n%endcal%`n`n%pr1%
return
;=========================================================================

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI > Position of edit field

Post by flyingDman » 28 Sep 2022, 08:46

Naitsirk wrote:
28 Sep 2022, 05:20
I really hope there is an easy way around this without have to put in coordinates.
Impossible with any coordinates. But just add x+3 like so:

Code: Select all

Gui, 2:Add, Edit, x+3 vPR1
14.3 & 1.3.7

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: GUI > Position of edit field

Post by garry » 28 Sep 2022, 08:59

'autopositioning' I used in a loop, otherwise it was fast written with x y w h -positions

Code: Select all

wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;-
x:=(wa*20)/xx,y:=(ha*30)/xx,w:=(wa*8)/xx,h:=(ha*2.5)/xx
Gui, 2:Add, Button      ,x%x% y%y%  w%w% h%h% ,Button-1
x:=(wa*28.5)/xx ;  < next x position =  x20 + w8  )
Gui, 2:Add, Button      ,x%x% y%y%  w%w% h%h% ,Button-2
;-

Naitsirk
Posts: 40
Joined: 15 Feb 2022, 03:50

Re: GUI > Position of edit field

Post by Naitsirk » 28 Sep 2022, 09:00

garry wrote:
28 Sep 2022, 08:27
@mikeyww works fine , here I added complicated always x y w h

@Naitsirk here I used always x y w h ( with percent calculation , depending screensize , Example x:=(wa*50)/xx means x-position from GUI should be in the middle of screen
or just can add , as example : Gui,add,button ,x100 y200 w100 h30 gA1 ,OK ;- here gA1 is the label A1 , the x and y-position is inside the GUI
( a danish movie for children , Olsenbanden 1968 - ( german geoblocked ) > https://mediathekviewweb.de/#query=olsenband )

Code: Select all

Gui,1:default
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100

Gui,1: -DPIScale
color=D4D0C8 
Gui,1:Color,Black,%color%
Gui,1:font,s12 cBlack,Lucida Console

x:=(wa*1)/xx,y:=(ha*1)/xx
Gui,Add, Text        , x%x%  y%y%        , Booking type:

x:=(wa*1)/xx,y:=(ha*3)/xx,w:=(wa*15)/xx,h:=(ha*15)/xx
Gui,Add, DropDownList, x%x%  y%y%  w%w% h%h% vPM     , Pakkerejse|Flybillet

x:=(wa*17)/xx,y:=(ha*3)/xx,w:=(wa*3)/xx,h:=(ha*2.4)/xx
Gui,Add, Button      , x%x% y%y%  w%w% h%h% gA1, OK

x:=(wa*10)/xx,y:=(ha*10)/xx,w:=(wa*25)/xx,h:=(ha*10)/xx
Gui,Show,x%x% y%y% w%w% h%h% ,Travel booking
GuiControl,1: Choose,PM,1
return
;------------
Guiclose:
Exitapp
;------------
A1:
Gui, Submit,nohide
If (Pm = "Pakkerejse")
 gosub,2ndgui
Return
;--------------
2ndGUI:
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
Gui,2: -DPIScale
color=D4D0C8 
Gui,2:Color,Black,%color%
Gui,2:font,s12 cYellow,Lucida Console
;--
x:=(wa*1 )/xx,y:=(ha*1)/xx
Gui, 2:Add, Text        ,x%x%  y%y%                       , Afrejsedato

x:=(wa*1 )/xx,y:=(ha*3)/xx,w:=(wa*25)/xx,h:=(ha*25)/xx
Gui, 2:Add, MonthCal    ,x%x% y%y%  w%w% h%h%   vStartCal

x:=(wa*28)/xx,y:=(ha*1)/xx
Gui, 2:Add, Text        ,x%x% y%y%                       , Hjemrejsedato

x:=(wa*28)/xx,y:=(ha*3)/xx,w:=(wa*25)/xx,h:=(ha*25)/xx
Gui, 2:Add, MonthCal    ,x%x% y%y%  w%w% h%h%   vEndCal

x:=(wa*1 )/xx,y:=(ha*30)/xx
Gui, 2:Add, Text        ,x%x%  y%y%                       , Fra lufthavn:

x:=(wa*8 )/xx,y:=(ha*30)/xx,w:=(wa*10)/xx,h:=(ha*2.5)/xx
Gui, 2:Add, Edit        ,x%x% y%y%  w%w% h%h% cBlack    vPR1 , Københavns Lufthavn

x:=(wa*20)/xx,y:=(ha*30)/xx,w:=(wa*4)/xx,h:=(ha*2.5)/xx
Gui, 2:Add, Button      ,x%x% y%y%  w%w% h%h%  gA2   , OK

x:=(wa*10)/xx,y:=(ha*23)/xx,w:=(wa*55)/xx,h:=(ha*45)/xx
Gui, 2:Show,x%x% y%y%  w%w% h%h% , Package deal
return
;------------
2GuiClose:
Gui,2:destroy
return
;exitapp
;------------

A2:
Gui, 2:Submit,nohide
msgbox,START=`n%startcal%`n`nEND=`n%endcal%`n`n%pr1%
return
;=========================================================================
Kunne godt have brugt lidt mere forberedelsestid, inden der blev kastet med olsenbanden-referencer i dette forum... :D

Naitsirk
Posts: 40
Joined: 15 Feb 2022, 03:50

Re: GUI > Position of edit field

Post by Naitsirk » 28 Sep 2022, 09:05

flyingDman wrote:
28 Sep 2022, 08:46
Naitsirk wrote:
28 Sep 2022, 05:20
I really hope there is an easy way around this without have to put in coordinates.
Impossible with any coordinates. But just add x+3 like so:

Code: Select all

Gui, 2:Add, Edit, x+3 vPR1
Dude, as always, thanks.

This sorta did the trick, but something is off:

Code: Select all

Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text, ym Section, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Add, Text, xm y+10, Fra lufthavn:
Gui, 2:Add, Edit, x+3 vPR1
Gui, 2:Add, Text, xm y+10, Til lufthavn:
Gui, 2:Add, Edit, x+4 vPR2
Gui, 2:Add, Button, default, OK  
Gui, 2:Show,, Package deal
return  

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

Re: GUI > Position of edit field  Topic is solved

Post by mikeyww » 28 Sep 2022, 09:56

Code: Select all

Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text, ym Section, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Add, Text, xm y+10 w60, Fra lufthavn:
Gui, 2:Add, Edit, x+m vPR1
Gui, 2:Add, Text, xm y+10 w60, Til lufthavn:
Gui, 2:Add, Edit, x+m vPR2
Gui, 2:Add, Button, default, OK
Gui, 2:Show,, Package deal
I usually try to simplify my approach to GUIs. Controls are added vertically by default. x+m is a convenient way to add a control to the right. You have a choice of whether to list all controls in a column, or go row by row. I often go column by column, but it depends on the specific layout. In the example above, I specified w60 for both text controls, because that lets x+m left-align the two corresponding edit controls.

Opposite approach:

Code: Select all

Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text, ym, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Add, Text, xm Section, Fra lufthavn:
Gui, 2:Add, Text,, Til lufthavn:
Gui, 2:Add, Edit, vPR1 ys
Gui, 2:Add, Edit, vPR2
Gui, 2:Add, Button, default, OK
Gui, 2:Show,, Package deal

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GUI > Position of edit field

Post by BoBo » 28 Sep 2022, 10:00

As said, it's a quite easy task to create a GUI bc you only have to deal with x/y to position, and w/h to scale a control.

Just like your screen (A_ScreenWidth/-Height) - you can see your GUI as a frame where its boundaries are set up using "width" and "height".
Gui, Show, w400 h200, Rectangle

Within that frame, your controls are positioned relative to that boundary.
Gui, Add, Text, x10 y20 w100 h18, GuiText ; positioned 10px from the left/20px from the top with a width of 100 and a height of 18
Adding the following control with the same coord-parameters would layer the second control over the previous control.
...which makes no sense, so let's shift it on that virtual grid to the right...
Gui, Add, Edit, xp+110 yp wp hp, <edit here!> ;xp(revious)+110 will postion that control 120px from the left, 20px from the top with a width of 100 and a height of 18

HTH

Naitsirk
Posts: 40
Joined: 15 Feb 2022, 03:50

Re: GUI > Position of edit field

Post by Naitsirk » 28 Sep 2022, 13:22

mikeyww wrote:
28 Sep 2022, 09:56

Code: Select all

Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text, ym Section, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Add, Text, xm y+10 w60, Fra lufthavn:
Gui, 2:Add, Edit, x+m vPR1
Gui, 2:Add, Text, xm y+10 w60, Til lufthavn:
Gui, 2:Add, Edit, x+m vPR2
Gui, 2:Add, Button, default, OK
Gui, 2:Show,, Package deal
I usually try to simplify my approach to GUIs. Controls are added vertically by default. x+m is a convenient way to add a control to the right. You have a choice of whether to list all controls in a column, or go row by row. I often go column by column, but it depends on the specific layout. In the example above, I specified w60 for both text controls, because that lets x+m left-align the two corresponding edit controls.

Opposite approach:

Code: Select all

Gui, 2:Destroy
Gui, 2:Add, Text,, Afrejsedato
Gui, 2:Add, MonthCal, vMyCalendar
Gui, 2:Add, Text, ym, Hjemrejsedato
Gui, 2:Add, MonthCal, vMyCalendar1
Gui, 2:Add, Text, xm Section, Fra lufthavn:
Gui, 2:Add, Text,, Til lufthavn:
Gui, 2:Add, Edit, vPR1 ys
Gui, 2:Add, Edit, vPR2
Gui, 2:Add, Button, default, OK
Gui, 2:Show,, Package deal
Your top code did it for me: adding the "xm" and "x+m"... do I understand why it needs to be put in, no, but hey, it works.

This tool rock, and so does this forum.

Thanks all... :bravo: :dance:

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: GUI > Position of edit field

Post by garry » 28 Sep 2022, 13:37

@mikeyww @BoBo @flyingDman thank you all for the good examples
I was too lazy to think , that's because I used coordinates x y w h ... :)

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

Re: GUI > Position of edit field

Post by mikeyww » 28 Sep 2022, 16:05

I was too lazy to think, so I used x+m.
:)

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: GUI > Position of edit field

Post by garry » 29 Sep 2022, 03:08

@mikeyww yes , that's easier and script is shorter ....

Post Reply

Return to “Ask for Help (v1)”