simple square of my size, my location with my text

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
guldamkwak
Posts: 7
Joined: 08 Dec 2021, 05:52

simple square of my size, my location with my text

Post by guldamkwak » 08 Dec 2021, 05:54

I just want to show a simple square, possibly transparent, of my size, my location , with my text inside of it. Can you give me a simple code snippet illustrates how to do this?
thanks.

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

Re: simple square of my size, my location with my text

Post by mikeyww » 08 Dec 2021, 06:32

Code: Select all

square1 := square(100, 100, 200, "Yellow", "My text"   , 20, 150)
square2 := square(500, 500, 100, "Red"   , "Red square", 10)

square(x, y, boxEdge, color, text, fontSize, transparency := 255) { ; Show a colored square with text
 ; https://www.autohotkey.com/boards/viewtopic.php?p=433517#p433517
 textY := (boxEdge - fontSize * A_ScreenDPI / 72) / 2
 Gui, New, -Caption -Border +LastFound +HwndhWnd
 Gui, Font, s%fontSize%
 Gui, Margin, 0, 0
 Gui, Add, Progress, w%boxEdge% h%boxEdge% c%color%, 100
 Gui, Add, Text    , xm y%textY% wp BackgroundTrans Center, %text%
 Gui, Show, x%x% y%y%, Square
 WinSet, Transparent, %transparency%
 Return hWnd
}

guldamkwak
Posts: 7
Joined: 08 Dec 2021, 05:52

Re: simple square of my size, my location with my text

Post by guldamkwak » 08 Dec 2021, 09:16

Can I make it without ?
image.png
image.png (4.96 KiB) Viewed 486 times

mikeyww wrote:
08 Dec 2021, 06:32

Code: Select all

square1 := square(100, 100, 200, "Yellow", "My text"   , 20, 150)
square2 := square(500, 500, 100, "Red"   , "Red square", 10)

square(x, y, boxEdge, color, text, fontSize, transparency := 255) { ; Show a colored square with text
 ; https://www.autohotkey.com/boards/viewtopic.php?p=433517#p433517
 textY := (boxEdge - fontSize * A_ScreenDPI / 72) / 2
 Gui, New, -Caption -Border +LastFound +HwndhWnd
 Gui, Font, s%fontSize%
 Gui, Margin, 0, 0
 Gui, Add, Progress, w%boxEdge% h%boxEdge% c%color%, 100
 Gui, Add, Text    , xm y%textY% wp BackgroundTrans Center, %text%
 Gui, Show, x%x% y%y%, Square
 WinSet, Transparent, %transparency%
 Return hWnd
}

guldamkwak
Posts: 7
Joined: 08 Dec 2021, 05:52

Re: simple square of my size, my location with my text

Post by guldamkwak » 08 Dec 2021, 09:59

i Want different sqaures show at the same time. How Can i do that?


mikeyww wrote:
08 Dec 2021, 06:32

Code: Select all

square1 := square(100, 100, 200, "Yellow", "My text"   , 20, 150)
square2 := square(500, 500, 100, "Red"   , "Red square", 10)

square(x, y, boxEdge, color, text, fontSize, transparency := 255) { ; Show a colored square with text
 ; https://www.autohotkey.com/boards/viewtopic.php?p=433517#p433517
 textY := (boxEdge - fontSize * A_ScreenDPI / 72) / 2
 Gui, New, -Caption -Border +LastFound +HwndhWnd
 Gui, Font, s%fontSize%
 Gui, Margin, 0, 0
 Gui, Add, Progress, w%boxEdge% h%boxEdge% c%color%, 100
 Gui, Add, Text    , xm y%textY% wp BackgroundTrans Center, %text%
 Gui, Show, x%x% y%y%, Square
 WinSet, Transparent, %transparency%
 Return hWnd
}

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

Re: simple square of my size, my location with my text

Post by mikeyww » 08 Dec 2021, 16:55

Try running this script by itself as a first step.

Code: Select all

square1 := square(100, 100, 200, "Yellow", "My text"   , 20, 150)
square2 := square(500, 500, 100, "Red"   , "Red square", 10)

square(x, y, boxEdge, color, text, fontSize, transparency := 255) { ; Show a colored square with text
 ; https://www.autohotkey.com/boards/viewtopic.php?p=433517#p433517
 textY := (boxEdge - fontSize * A_ScreenDPI / 72) / 2
 Gui, New, -Caption -Border +LastFound +HwndhWnd +Owner
 Gui, Font, s%fontSize%
 Gui, Margin, 0, 0
 Gui, Add, Progress, w%boxEdge% h%boxEdge% c%color%, 100
 Gui, Add, Text    , xm y%textY% wp BackgroundTrans Center, %text%
 Gui, Show, x%x% y%y%, Square
 WinSet, Transparent, %transparency%
 Return hWnd
}
image211208-1700-001_cr-75.png
Output
image211208-1700-001_cr-75.png (134.56 KiB) Viewed 457 times

guldamkwak
Posts: 7
Joined: 08 Dec 2021, 05:52

Re: simple square of my size, my location with my text

Post by guldamkwak » 08 Dec 2021, 22:35

In that case, If I add more and more squares, than the former squares appear fisrt. For example square1 apperas first than square2

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

Re: simple square of my size, my location with my text

Post by mikeyww » 09 Dec 2021, 05:42

You can change the order to be whatever you want. What the script does: "i Want different sqaures show at the same time."

Post Reply

Return to “Ask for Help (v1)”