I have edited the codes as follows.
There is also a sample code for this on the autohotkey help page.
https://www.autohotkey.com/docs/v2/lib/Gui.htm#ExEditor
#Requires AutoHotkey 2.0
TextBoxGUI := Gui("+Resize", "TextBox GUI")
TextBoxGUI.OnEvent("Size", ResizeWindow)
TextBoxGUI.SetFont("s15 Norm", "Lexend")
EditBox := TextBoxGUI.Add("Edit", "x0 y0 w500 h600")
TextBoxGUI.Show("w500 h600")
ResizeWindow(GuiObj, MinMax, Width, Height) {
if MinMax = -1 ; The window has been minimized. No action needed.
return
EditBox.Move(,,Width,Height)
}