How to update text control width after the content change?

Get help with using AutoHotkey and its commands and hotkeys
think
Posts: 65
Joined: 09 Feb 2014, 05:20

How to update text control width after the content change?

20 Oct 2019, 15:57

I have few gui text controls in the row which must maintain a standard spacing between them. User can rename any of the strings. In the example below, after changing the first text control content, the control width should be updated to show the new text and keep the distance to the second. Any idea how to do this? Thanks.

Code: Select all

gui, add, text, x10 y10 vt1, Text 
GuiControlGet, Pos, Pos, t1
p:=PosX+PosW+10
gui, add, text, x%p% yp vt2, Text
gui, show, w200 h100

sleep 1000

GuiControl,, t1, NewText
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: How to update text control width after the content change?

20 Oct 2019, 19:17

Something like this might do it for you.

If not, I think that there is a "measure string" DLLCall etc that can be used to get the required size adjustments. I don't know what it is so I can't post a example using it.

This method (or similar) has always been good enough for me.

Code: Select all

#SingleInstance,Force
Gui,1:+AlwaysOnTop
Gui,1:Add,Text,x10 y10 r1 vt1, Text 1
Gui,1:Add,Text,x+10 r1 vt2, Text 2
Gui,1:Add,Edit,xm y+20 w100 r1 vTextEdit1 gUpdate,New text 1 
Gui,1:Add,Edit,xm  w100 r1 vTextEdit2 gUpdate,New text 2 
gui, show, w200 h100
return
GuiClose:
GuiContextMenu:
*Esc::
   ExitApp
   
Update:
   Gui,1:Submit,NoHide
   if(A_GuiControl="TextEdit1"){
      Gui,FakeGui:Add,Text,x10 r1 vFakeTextControl,% TextEdit1
      GuiControlGet,Pos,FakeGui:Pos,FakeTextControl
      Gui,FakeGui:Destroy
      GuiControl,Move,t2,% "x" PosX+PosW+10
      GuiControl,Move,t1,% "w" PosW
      GuiControl,,t1,% TextEdit1
   }else    {
      Gui,FakeGui:Add,Text,x10 r1 vFakeTextControl,% TextEdit2
      GuiControlGet,Pos,FakeGui:Pos,FakeTextControl
      Gui,FakeGui:Destroy
      GuiControl,Move,t2,% "w" PosW
      GuiControl,,t2,% TextEdit2
   }
   return

Return to “Ask For Help”

Who is online

Users browsing this forum: 4k3or3et, Bing [Bot], blenderfish, boiler, coder_chick, DaveT1, hackkk745, moszt, RubbeH, TheDewd and 48 guests