POSITION OF THE TEXT CONTROL

Get help with using AutoHotkey and its commands and hotkeys
MonuKashyap
Posts: 49
Joined: 06 Jun 2016, 21:32

POSITION OF THE TEXT CONTROL

02 Dec 2018, 01:43

assume

loop 6
Gui, add, text,, % a_index

;; in this, how can we know that what will be coordinates (x, y) of the text control
is there any built-in-variable for that??
any idea?
wolf_II
Posts: 2687
Joined: 08 Feb 2015, 20:55

Re: POSITION OF THE TEXT CONTROL

02 Dec 2018, 03:13

Try this:

Code: Select all

#NoEnv
#SingleInstance, Force
Loop 6
    Gui, Add, Text,, %A_Index%
Gui, Add, Button,, Get Coords
Gui, Show, w250
return

GuiClose:
ExitApp

ButtonGetCoords:
    List := ""
    Loop 6 {
        GuiControlGet, pos, Pos, Static%A_Index%
        List .= A_Index ": X=" posX " Y=" posY "`tW=" posW " H=" posH "`n"
    }
    MsgBox, %List%
return
I hope that helps.
wolf_II
Posts: 2687
Joined: 08 Feb 2015, 20:55

Re: POSITION OF THE TEXT CONTROL

02 Dec 2018, 05:14

also with dragging, Try this:

Code: Select all

#NoEnv
#SingleInstance, Force
Loop 6
    Gui, Add, Text,, %A_Index%
Gui, Add, Button,, Get Coords
Gui, Show, x200 w800 h800
return

GuiClose:
ExitApp

ButtonGetCoords:
    List := ""
    Loop 6 {
        GuiControl, +Border, Static%A_Index%
        GuiControl, Move, Static%A_Index%, w160
        GuiControlGet, pos, Pos, Static%A_Index%
        Text := "X=" posX " Y=" posY "`tW=" posW " H=" posH
        GuiControl,, Static%A_Index%, %Text%
        List .= A_Index ": " Text "`n"
    }
    MsgBox, %List%
    Hotkey, ~LButton, onLButton
    Gui, Show,, Start Dragging
return

onLButton:
    MouseGetPos, mouseX, mouseY,, Ctrl
    if !InStr(Ctrl, "Static")
        return
    GuiControlGet, pos, Pos, %Ctrl%
    dx := mouseX - posX, dy := mouseY - posY
    while GetKeyState("LButton", "P") {
        MouseGetPos, mouseX, mouseY
        GuiControl, MoveDraw, %Ctrl%, % "x" mouseX - dx " y" mouseY - dy
        Text := "X=" mouseX - dx " Y=" mouseY - dy "`tW=" posW " H=" posH
        GuiControl,, %Ctrl%, %Text%
    }
return
I hope that helps.
User avatar
jeeswg
Posts: 6708
Joined: 19 Dec 2016, 01:58
Location: UK

Re: POSITION OF THE TEXT CONTROL

02 Dec 2018, 18:29

- I found this in the documentation:
Gui - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/Gui.htm#Margin
If this command is not used, when the first control is added to a window, the window acquires a default margin on all sides proportional to the size of the currently selected font (0.75 times font-height for top & bottom, and 1.25 times font-height for left & right).
- I did some experiments commenting/uncommenting the lines below. It appears that the font size determines the margin sizes and space between controls. However, if the Gui-Margin subcommand is used, that overrides it.
- Another issue is that the gap sizes appear to differ depending on the control type. Maybe there are specific values for each control type. Cheers.

Code: Select all

vCtlType := "Text"
vCtlType := "Edit"
;vSize := 36
;vSize := 72
;vSize := 0
Gui, Margin, 0, 0
Gui, Margin, 100, 100
Gui, Font, % "s" vSize
Loop, 6
	Gui, Add, % vCtlType,, % A_Index
Gui, Show
return
- Btw one thing to be aware of is to use client coordinates (coordinates relative to the client area) to get control positions, instead of coordinates relative to the window.
convert coordinates between Client/Screen/Window modes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=38472
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Rohwedder, Trymado and 234 guests