How to autosize the edit box? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
alexsu
Posts: 97
Joined: 16 Jul 2020, 05:32

How to autosize the edit box?

Post by alexsu » 13 Mar 2023, 08:03

For example, here is an ahk script, I want the Edit boxes‘ size can be changed with the gui size. How to make it out?Thanks

Code: Select all

Gui, +Resize
Gui, Add, Edit, x10, y10 w480 h180
Gui, Show, w500 h250


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

Re: How to autosize the edit box?

Post by mikeyww » 13 Mar 2023, 08:12

Code: Select all

; This script shows how to resize a control
#Requires AutoHotkey v1.1.33
Gui +Resize
Gui Font, s10
Gui Add, Edit, w480 h180 ved
Gui Show
Return

GuiSize(GuiHwnd, eventInfo, width, height) {
 If (eventInfo != MINIMIZED := 1)
  GuiControl Move, ed, % "w" width - 25 "h" height - 15
}
Explained: GuiSize

alexsu
Posts: 97
Joined: 16 Jul 2020, 05:32

Re: How to autosize the edit box?

Post by alexsu » 13 Mar 2023, 09:09

I have a progress bar in the gui, I want to the progress bar (Size: w500 h55) always displays on the bottom of gui. The progress bar's height always keeps h55, the width can be changed with gui. Then how to do it? Thanks
mikeyww wrote:
13 Mar 2023, 08:12

Code: Select all

; This script shows how to resize a control
#Requires AutoHotkey v1.1.33
Gui +Resize
Gui Font, s10
Gui Add, Edit, w480 h180 ved
Gui Show
Return

GuiSize(GuiHwnd, eventInfo, width, height) {
 If (eventInfo != MINIMIZED := 1)
  GuiControl Move, ed, % "w" width - 25 "h" height - 15
}
Explained: GuiSize

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

Re: How to autosize the edit box?

Post by mikeyww » 13 Mar 2023, 09:14

Same way. Move the control to the bottom. You can set the y-value. See example.

gmoises
Posts: 75
Joined: 18 Nov 2017, 16:43

Re: How to autosize the edit box?

Post by gmoises » 13 Mar 2023, 09:21

Code: Select all

#Requires AutoHotkey v1.1.36+

Gui, +Resize 
Gui, Add, Edit, x10 y10 w480 h180 +HWNDhwnd
Gui, Show, w500 h250
Return

GuiSize:
	ControlMove, , , , A_GuiWidth - 10, A_GuiHeight - 60, ahk_id %hwnd%
Return

GuiClose:
	ExitApp

alexsu
Posts: 97
Joined: 16 Jul 2020, 05:32

Re: How to autosize the edit box?

Post by alexsu » 13 Mar 2023, 09:35

How to set the the progress bar always on the bottom of the gui, I don't know how to do it. Very difficult for me
mikeyww wrote:
13 Mar 2023, 09:14
Same way. Move the control to the bottom. You can set the y-value. See example.

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

Re: How to autosize the edit box?

Post by mikeyww » 13 Mar 2023, 09:49

Code: Select all

; This script moves GUI controls when the GUI is resized.
#Requires AutoHotkey v1.1.33
Gui +Resize
Gui Font, s10
Gui Add, Edit    , w480 h180 ved
Gui Add, Progress, wp   h20  vprog cBlue, 100
Gui Show
Return

GuiSize(GuiHwnd, eventInfo, width, height) {
 If (eventInfo != MINIMIZED := 1) {
  GuiControl Move, ed  , % "w" width - 25 "h" height - 40
  GuiControl Move, prog, % "w" width - 25 "y" height - 27
 }
}

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: How to autosize the edit box?

Post by RDC » 13 Mar 2023, 10:03

Just curious Mikey,
in the line " Gui Add, Edit, w480 h180 ved "... what is the "ved"? If I delete it I see no changes.

Also, alexsu
...adding the below just before the Return line works great with the original posted script for me.

Code: Select all

;  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  
Gui, Font, s12 w567 c000000, Segoe UI
Gui, Add, Text, x30, Progressing...

Gui, Add, Progress, x10 y+1 w160 h10 cBLUE Background000000 Range1-48 vMyProgress

Gui, Font, s9 w300 cRED, Segoe UI
Gui, Add, Text, x30 Y+1, Other Text as example.

gui, show

GuiControl,, MyProgress, 0
Loop, 48
{
  GuiControl,, MyProgress, +1
   Sleep, 16
}

Sleep 750
SoundBeep, 1200, 200
SoundBeep, 1250, 100

Gui, Destroy
;  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  

Return
Last edited by RDC on 13 Mar 2023, 10:07, edited 1 time in total.

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

Re: How to autosize the edit box?

Post by mikeyww » 13 Mar 2023, 10:06

Here is where a peek at the documentation can help you.

Storing and responding to user input:
V: Variable. Associates a variable with a control. Immediately after the letter V, specify the name of a global variable (or a ByRef local that points to a global, or [in v1.0.46.01+] a static variable). For example, specifying vMyEdit would store the control's contents in the variable MyEdit whenever the Gui Submit command is used. If a control is not input-capable -- such as a Text control or GroupBox -- associating a variable with it can still be helpful since that variable's name serves as the control's unique identifier for use with the ControlID parameter of GuiControl and GuiControlGet, and with A_GuiControl.
You saw no changes when removing ved because you did not resize the GUI, and you did not attempt to retrieve the control's value (contents).

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: How to autosize the edit box?

Post by RDC » 13 Mar 2023, 10:09

Thank you for my part. Something more for me to research now!

alexsu
Posts: 97
Joined: 16 Jul 2020, 05:32

Re: How to autosize the edit box?

Post by alexsu » 13 Mar 2023, 10:41

It works well for edit box and progress bar, not works well for text.
The text (hello)will not display if gui’s height is changed. How to revise it?
For example, There is a text in this gui

Code: Select all

#Requires AutoHotkey v1.1.33
Gui +Resize
Gui Font, s10
Gui Add, Edit    , w480 h180 ved
Gui Add, Progress,  x0 wp   h55  vprog cBlue, 100
Gui, Font, s12
Gui Add, Text, x10 vte, hello
Gui Show
Return

GuiSize(GuiHwnd, eventInfo, width, height) {
 If (eventInfo != MINIMIZED := 1) {
  GuiControl Move, ed  , % "w" width - 25 "h" height - 65
  GuiControl Move, prog, % "w" width - 0 "y" height - 40
  GuiControl Move, te, % "y" height -40
 }
}
mikeyww wrote:
13 Mar 2023, 09:49

Code: Select all

; This script moves GUI controls when the GUI is resized.
#Requires AutoHotkey v1.1.33
Gui +Resize
Gui Font, s10
Gui Add, Edit    , w480 h180 ved
Gui Add, Progress, wp   h20  vprog cBlue, 100
Gui Show
Return

GuiSize(GuiHwnd, eventInfo, width, height) {
 If (eventInfo != MINIMIZED := 1) {
  GuiControl Move, ed  , % "w" width - 25 "h" height - 40
  GuiControl Move, prog, % "w" width - 25 "y" height - 27
 }
}


Post Reply

Return to “Ask for Help (v1)”