AutoHotkey GUI: x+m with additional offset

Get help with using AutoHotkey and its commands and hotkeys
hotkeyguy
Posts: 149
Joined: 11 Oct 2014, 12:22

AutoHotkey GUI: x+m with additional offset

24 Sep 2016, 11:13

Hello,

from the help:
For example, x+m uses the right edge of the previous control plus the standard padding distance.
I have no luck with an additional offset like

Code: Select all

Gui, Add, Button,   % "x+m" - 20 ...
Gui, Add, Button,   % "x+m" + 20 ...
What I want to achieve is to position a control right to the left one with a certain gap (offset) without much calculations (value/variable for the width of the left control), like needed with xp+n.


Many thanks and greetings
hotkeyguy
hunter99
Posts: 128
Joined: 20 Jan 2014, 17:57

Re: AutoHotkey GUI: x+m with additional offset

24 Sep 2016, 15:32

Hi, this what you want?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, Margin, -2,
Gui, font, s8

Gui, Add, Button, w100 h50  ym, X Margin = -2`nY Margin =padding
Gui, Add, Button, w100 h50  ym, X Margin = -2`nY Margin =padding
Gui, Add, Button, w100 h50  ym, X Margin = -2`nY Margin =padding

; this sets the margin and uses both margin and positioning
Gui, Margin,-2, 60
Gui, Add, Button, w100 h50 xm ym ,  xm ym
Gui, Add, Button, w100 h50 xp+100 ym,  xp+100  ym
Gui, Add, Button, w100 h50 xp+100 ym ,  xp+100  ym

; no margin used here takes margin above.
; use of 48 and 98 instead of 50 and 100 removes padding.
; padding is machine dependent.
Gui, Add, Button, w100 h50 xm ym+48, xm  ym+48
Gui, Add, Button, w100 h50 xp+98 yp, xp+98  yp
Gui, Add, Button, w100 h50 xp+98 yp, xp+98  yp
Gui, Add, Button, w100 h50 xp+98 yp, xp+98  yp
Gui, Add, Button, w100 h50 xp+98 yp, xp+98  yp
Gui Show, w550 h200, Margin Examples
Also check the docs here:https://autohotkey.com/docs/commands/Gui.htm#Position
You also might want to get a copy of CodeQuicktester by GeekDude from here:https://autohotkey.com/boards/viewtopic.php?f=6&t=6113
good luck, hunter
lexikos
Posts: 6968
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: AutoHotkey GUI: x+m with additional offset

24 Sep 2016, 17:35

@hotkeyguy: It's not supported.

Instead, you must set or retrieve the margin yourself and use that in your calculation. If you've added a control at the margins or with the standard offset from the previous control, you can use GuiControlGet Pos to retrieve the margin.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Google [Bot], jasonsparc, Odlanir, rhaos, Sabestian Caine, Sefrautic, Smile_ and 37 guests