Gui text field does not span multiple lines when text is changed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Gui text field does not span multiple lines when text is changed

25 May 2018, 16:19

I am trying to change a TEXT control in a GUI, such that, when I change the text, the "word wrap" facility of a TEXT control takes effect.

At GUI/ADD TEXT, the doc says:
If a width (W) is specified in Options but no rows (R) or height (H), the text will be word-wrapped as needed, and the control's height will be set automatically.
Additionally, he doc says at GUICONTROL, TEXT:
Text/Button/GroupBox/StatusBar/Link: Specify for Param3 the control's new text. Since the control will not expand automatically, use GuiControl, Move, MyText, W300 if the control needs to be widened.
And, thus, the reason I have included the GUICONTROL, MOVE commands in my sample below. (It does, however, seem to do nothing, since I'm not wanting to change the Width.

I want to change a text control that I have already created and have the new text act as if the ROW and/or HEIGHT parameter is not specified. Is this possible?

Here is what I tried, which doesn't work.

ALT+CTL + F10 changes the text as does ALT+CTL+F11 (the difference the sequence of Guicontrol commands)

Code: Select all

txt1 := "TXT1:  This is a test. TXT1"
txt2 := "TXT2:  This is a test.  However this is much more text much much much more TXT2"
txt3 := "TXT3:  This is a test.  However this is much more text much much much more TXT3"
Gui, color,Black
Gui, Font, cFF00000  s16
Gui, Add, Text, x25 y25 w400 vTestTxt, %txt1%
Gui, Show, w500 h300 x1 y1, TEST
return

!^F12:: exitapp

!^F10::
   GuiControl, move, TestTxt, w450
   GuiControl, , TestTxt, %txt2%
   return

!^F11::
   GuiControl, , TestTxt, %txt3%
   GuiControl, move, TestTxt, w450
   return
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui text field does not span multiple lines when text is changed

25 May 2018, 17:03

This is how I have done this in the past. It's not pretty, but gets it done

Code: Select all

#SingleInstance,Force


txt1 := "TXT1:  This is a test. TXT1"
txt2 := "TXT2:  This is a test.  However this is much more text much much much more TXT2"
txt3 := "TXT3:  This is a test.  However this is much more text much much much more TXT3"
Gui, color,Black
Gui, Font, cFF00000  s16
Gui, Add, Text, x25 y25 w400 vTestTxt, %txt1%
Gui, Show, w500 h300 x1 y1, TEST
return
GuiClose:
*^Esc:: 
exitapp





*Numpad1::
	;Shit I added
	;----------------------------------------
	Gui,6: Font, cFF00000  s16
	Gui,6:Add,Text,x0 y0 w400 vit ,%txt2%
	GuiControlget,pos,6:pos,it
	Gui,6:Destroy
	GuiControl, move, TestTxt, w%posw% h%posh%
	;-----------------------------------------
   
   ;~ GuiControl, move, TestTxt, w450
   GuiControl, , TestTxt, %txt2%
   return

*Numpad2::
	;Shit I added
	;----------------------------------------
	Gui,6: Font, cFF00000  s16
	Gui,6:Add,Text,w400 vit ,%txt3%
	GuiControlget,pos,6:pos,it
	Gui,6:Destroy
	GuiControl, move, TestTxt, w%posw% h%posh%
	;-----------------------------------------
   GuiControl, , TestTxt, %txt3%
   ;~ GuiControl, move, TestTxt, w450
   return
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Gui text field does not span multiple lines when text is changed

28 May 2018, 17:52

it's not pretty. What I am trying to avoid is "Gui, destroy". That really isn't changing the GUI.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui text field does not span multiple lines when text is changed

28 May 2018, 18:36

It is not destroying your gui, it is making a temp gui with your new text so that it can get the height of it to add to yours.
The gui that is made is not even ever shown.
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: Gui text field does not span multiple lines when text is changed

28 May 2018, 19:28

You cannot change the word wrap ability of a edit box control once it is created. in any language in windows... that is true for most the abilities/variants of the edit box control as specified, ultimately, by the styles parameters in the underlying windows API function call that creates the edit box window... I just did an intensive 3 months investigation in the edit box making it format and colorize code. it is extremely frustrating...

You have to create the control with the features you want from the start. if you want an edit box to work in multiple ways, you can always create invisible boxes with the wanted styles and make them visible when the need arises.
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Gui text field does not span multiple lines when text is changed

29 May 2018, 07:29

@Hellbent

My sincere apologies. I quickly browsed your code and saw "gui, destroy" and assumed that what you were doing was what was originally doing.

Thank you for taking the time to reply. I was indeed ignorant.

While your code is indeed messy, but it does what I want without destroying the first GUI. thank you!!

I wonder, however, if something is not "broken" with the automatic "word wrap" facility.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui text field does not span multiple lines when text is changed

29 May 2018, 07:34

joefiesta wrote: I wonder, however, if something is not "broken" with the automatic "word wrap" facility.
Not really a issue of it being broken, if you gave enough space for any text when you created the control it would have no problem adding all your text when you did the switch.
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Gui text field does not span multiple lines when text is changed

29 May 2018, 08:23

@Hellbent
Not really a issue of it being broken, if you gave enough space for any text when you created the control it would have no problem adding all your text when you did the switch.
I don't want my TEXT control to be wider than the GUI in which it occurs. And, since the additional text may be of any length, your method suits my needs. Maybe it isn't broken. I guess the answer is it could be improved. (But, is it worth it?)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, dipahk and 214 guests