Adding Text Containing Line Breaks to a Gui Window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Adding Text Containing Line Breaks to a Gui Window

Post by Alexander2 » 15 Aug 2022, 12:28

The following command adds the text “EXAMPLE” in the middle of a Gui window.

Code: Select all

gui add, text, xp yp wp hp cWhite Center 0x200 BackgroundTrans, EXAMPLE
Does anyone know what command can be used to add text which has line breaks?
For instance, the three lines
EXAMPLE
EXAMPLE
EXAMPLE
have to be added in the middle of a Gui window.

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

Re: Adding Text Containing Line Breaks to a Gui Window

Post by mikeyww » 15 Aug 2022, 19:56

Code: Select all

Gui, Add, Text,, EXAMPLE`nEXAMPLE`nEXAMPLE

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Adding Text Containing Line Breaks to a Gui Window

Post by Alexander2 » 16 Aug 2022, 12:02

mikeyww wrote:
15 Aug 2022, 19:56

Code: Select all

Gui, Add, Text,, EXAMPLE`nEXAMPLE`nEXAMPLE
I have tried adding ‘n to the beginning of the text which is to start on a new line, but the text is not started on a new line.
The script includes an image as the background.

Code: Select all

Gui, +AlwaysOnTop -Caption
Gui, Add, Picture, w1280 h900, F:\Data\zzMacroinstr\Scripts\reminders and actions\_image.jpg
Gui, Font, s70, Arial Black
gui add, text, xp yp wp hp cWhite Center 0x200 BackgroundTrans, EXAMPLE `nEXAMPLE
gui show
return

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

Re: Adding Text Containing Line Breaks to a Gui Window

Post by mikeyww » 16 Aug 2022, 12:53

Debugging is easy, because you started with a working script, made several changes without testing each of them, and ended with a broken script. Start over, and add one change at a time; retest until it breaks. You then have your answer. Try deleting 0x200 as a start.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Adding Text Containing Line Breaks to a Gui Window

Post by Alexander2 » 17 Aug 2022, 11:18

mikeyww wrote:
16 Aug 2022, 12:53
Debugging is easy, because you started with a working script, made several changes without testing each of them, and ended with a broken script. Start over, and add one change at a time; retest until it breaks. You then have your answer. Try deleting 0x200 as a start.
I have deleted the parameter 0x200 from the script. Now the two words are displayed one below the other in the middle. However, they are displayed at the top of the window. Is it possible to display the words one below the other in the center of the window, as in the picture below?
Untitled.png
Untitled.png (10.9 KiB) Viewed 912 times


Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Adding Text Containing Line Breaks to a Gui Window

Post by Alexander2 » 18 Aug 2022, 11:37

mikeyww wrote:
17 Aug 2022, 11:24
Yes. You would like to know how to specify x and y for a GUI or GUI controls. See:

https://www.autohotkey.com/docs/commands/Gui.htm#PosSize

and

https://www.autohotkey.com/docs/commands/Gui.htm#Show

Get a control's position & size: https://www.autohotkey.com/docs/commands/GuiControlGet.htm#Pos

Move or resize a control: https://www.autohotkey.com/docs/commands/GuiControl.htm#Move
Thank you for the instructions. They deal with individual controls. But it seems as if there is no way to put more than one line of text automatically in the center. A user has to specify exact locations.
AutoHotkey can center a single line. Can it automatically do the same for more than one line? Perhaps there is a way to treat multiple lines as a single block of text rather than as separate controls?

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

Re: Adding Text Containing Line Breaks to a Gui Window

Post by mikeyww » 18 Aug 2022, 11:55

The Center option works horizontally. You would have to determine the position for vertical adjustment, but it is achievable with the commands that I mentioned.

Post Reply

Return to “Ask for Help (v1)”