AutoXYWH() - Move control automatically when GUI resized
Re: AutoXYWH() - Move control automatically when GUI resized
Could someone with experience run a speed comparison against anchor() please? I have no real exp.
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
And another version.
The previous seemed to be overkill to redraw every control in Class 'Button' and storing too much unneeded data in the cInfo object.
Thus, for this version you will have to specify a * in DimSize to MoveDraw the controls rather then Move, which is recommended for groupboxes.
The previous seemed to be overkill to redraw every control in Class 'Button' and storing too much unneeded data in the cInfo object.
Thus, for this version you will have to specify a * in DimSize to MoveDraw the controls rather then Move, which is recommended for groupboxes.
Code: Select all
; =================================================================================
; Function: AutoXYWH
; Move and resize control automatically when GUI resizes.
; Parameters:
; DimSize - Can be one or more of x/y/w/h optional followed by a fraction
; add a '*' to DimSize to 'MoveDraw' the controls rather then just 'Move', this is recommended for Groupboxes
; cList - variadic list of ControlIDs
; ControlID can be a control HWND, associated variable name, ClassNN or displayed text.
; The later (displayed text) is possible but not recommend since not very reliable
; Examples:
; AutoXYWH("xy", "Btn1", "Btn2")
; AutoXYWH("w0.5 h 0.75", hEdit, "displayed text", "vLabel", "Button1")
; AutoXYWH("*w0.5 h 0.75", hGroupbox1, "GrbChoices")
; ---------------------------------------------------------------------------------
; Release date: 2014-7-03
; Author : tmplinshi (mod by toralf)
; requires AHK version : 1.1.13.01+
; =================================================================================
AutoXYWH(DimSize, cList*){ ; http://ahkscript.org/boards/viewtopic.php?t=1079
static cInfo := {}
For i, ctrl in cList {
ctrlID := A_Gui ":" ctrl
If ( cInfo[ctrlID].x = "" ){
GuiControlGet, i, %A_Gui%:Pos, %ctrl%
GuiControlGet, Hwnd, %A_Gui%:Hwnd, %ctrl%
MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move"
fx := fy := fw := fh := 0
For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]")))
If !RegExMatch(DimSize, "i)" dim "\s*\K[\d.-]+", f%dim%)
f%dim% := 1
cInfo[ctrlID] := { x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a , m:MMD}
}Else If ( cInfo[ctrlID].a.1) {
dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw , dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh
For i, dim in cInfo[ctrlID]["a"]
Options .= dim (dg%dim% * cInfo[ctrlID]["f" dim] + cInfo[ctrlID][dim]) A_Space
GuiControl, % A_Gui ":" cInfo[ctrlID].m , % ctrl, % Options
} } }
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
Yes, this is much neater than Anchor, thanks!
Nice to see it also works with HWNDS
Though personally I would make ctrl_list an indexed array - pipe delimited lists is a bit old-school surely?
Also, I used this to *almost* solve the issue of AHK not supporting scrollbars for GUIs.
The idea is to hijack a listview and insert images into the listview of a known height.
You then inject your controls, guis etc into the LV, and set the rows of the LV to the height of your GUI, and it handles the scrollbars for you.
You then use AutoXYWH to make the LV always fill the GUI.
Only problem is, the contents corrupt when the LV scrolls. If anyone can think of any solutions, please see my thread here: http://ahkscript.org/boards/viewtopic.p ... 205#p37205
Nice to see it also works with HWNDS
Code: Select all
#SingleInstance force
Gui, +Resize
Gui, Add, Edit , w200 hwndhEdit
Gui, Add, Button, ys w40 hp vBtn1, 1
Gui, Add, Button, ys wp hp hwndHwndBtn2, 2
Gui, Show
Return
GuiSize:
AutoXYWH(hEdit, "wh")
AutoXYWH("Btn1|" HwndBtn2, "hx")
Return
GuiClose:
ExitApp
Also, I used this to *almost* solve the issue of AHK not supporting scrollbars for GUIs.
The idea is to hijack a listview and insert images into the listview of a known height.
You then inject your controls, guis etc into the LV, and set the rows of the LV to the height of your GUI, and it handles the scrollbars for you.
You then use AutoXYWH to make the LV always fill the GUI.
Only problem is, the contents corrupt when the LV scrolls. If anyone can think of any solutions, please see my thread here: http://ahkscript.org/boards/viewtopic.p ... 205#p37205
Re: AutoXYWH() - Move control automatically when GUI resized
Wouldn't your post better be placed in the ask for help section instead of highjacking this thread?
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
Hi, great function! I have one question:
When some gui control (for example Edit control) in a window gets resized, the function does not work properly (doesn't consider the changed size of control). The problem was the same with Anchor. Please try the example below - press the button and then resize.
Any solution to this? How could this be solved? Thanks!
When some gui control (for example Edit control) in a window gets resized, the function does not work properly (doesn't consider the changed size of control). The problem was the same with Anchor. Please try the example below - press the button and then resize.
Any solution to this? How could this be solved? Thanks!
Code: Select all
#include AutoXYWH.ahk
Gui, +Resize
Gui, Add, Edit, ve1 w150 h100
Gui, Add, Button, vb1 gResize, Resize
Gui, Show
return
Resize:
GuiControl, Move, e1, h50
return
GuiSize:
AutoXYWH("wh", "e1")
AutoXYWH("y", "b1")
return
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
Re: AutoXYWH() - Move control automatically when GUI resized
Great!!! Thanks a lot!
Re: AutoXYWH() - Move control automatically when GUI resized
To m3user.
What you want is not supported by this function. You would need to change the function by e.g. adding a new parameter to reset the original size.
What you want is not supported by this function. You would need to change the function by e.g. adding a new parameter to reset the original size.
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
Thanks Toralf, I have no idea how to do this. Any help is appreciated.
Re: AutoXYWH() - Move control automatically when GUI resized
Thanks for this function, it finally sends Anchor to retirement. However I agree, it needs a reset option - would it be difficult to add?
Re: AutoXYWH() - Move control automatically when GUI resized
In general it should be possible. Somehow the function needs to know when that will be. Since the second parameter is an array the info has to be in the first parameter. Which would also make sense since it would be a reset of the dimensions.
What would be your suggestion on how to provide the info in the first parameter? E.g. an 'r' or a '*'?
But before something gets developed that is not needed please help to define the details:
When would a reset be required in addition to the above case? Why would it need to be reset? And what needs to be reset?
What would be your suggestion on how to provide the info in the first parameter? E.g. an 'r' or a '*'?
But before something gets developed that is not needed please help to define the details:
When would a reset be required in addition to the above case? Why would it need to be reset? And what needs to be reset?
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
The example posted above shows the issue clearly.
Reset could be called after any re-arrangement of the controls in gui window (typically by GuiControl, Move) by calling AutoXYWH("r", "e1") or similar after a resize or by simply calling AutoXYWH().
Reset could be called after any re-arrangement of the controls in gui window (typically by GuiControl, Move) by calling AutoXYWH("r", "e1") or similar after a resize or by simply calling AutoXYWH().
Re: AutoXYWH() - Move control automatically when GUI resized
Nice job!
Is it possible add/improve the following functions?
1. Set minimum GUI size to prevent controls squeezing together.
2. Set positions of multiple controls. for example: AutoXYWH("xy", "Button1-30" , "Edit1-30")
3. Eliminate blinking during resizing.
Thanks!
Is it possible add/improve the following functions?
1. Set minimum GUI size to prevent controls squeezing together.
2. Set positions of multiple controls. for example: AutoXYWH("xy", "Button1-30" , "Edit1-30")
3. Eliminate blinking during resizing.
Thanks!
Re: AutoXYWH() - Move control automatically when GUI resized
1) can be done via Gui, MinSize
2) I do not understand. Please elaborate
3) not possible
2) I do not understand. Please elaborate
3) not possible
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
Thank you toralf,
Currently I'm using code like this:
It will be nice it we can use the short code below:
Imagine that I have a GUI has 30 buttons and 30 edit boxes.toralf wrote:2) I do not understand. Please elaborate
Currently I'm using code like this:
Code: Select all
AutoXYWH("xy", "Button1" , "Button2","Button3" , "Button4".......)
AutoXYWH("xy", "Edit1" , "Edit2","Edit3" , "Edit4".......)
Code: Select all
AutoXYWH("xy", "Button1-30" , "Edit1-30")
Re: AutoXYWH() - Move control automatically when GUI resized
Guest wrote:Imagine that I have a GUI has 30 buttons and 30 edit boxes.
Code: Select all
#NoEnv
Controls := []
Loop, 30
Controls.Insert("Button" . A_Index)
Loop, 30
Controls.Insert("Edit" . A_Index)
VariadicFunc(Controls*)
ExitApp
VariadicFunc(Params*) {
For Each, Param In Params
MsgBox, 0, Param %A_Index%, %Param%
}
Re: AutoXYWH() - Move control automatically when GUI resized
Thanks just me.
AutoXYWH() is already a variadic function. Thus what just me wrote could directly be used with it.
AutoXYWH() is already a variadic function. Thus what just me wrote could directly be used with it.
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
Code: Select all
Controls := []
Loop, 30
Controls.Insert("Button" . A_Index), Controls.Insert("Edit" . A_Index)
AutoXYWH("xy", Controls*)
ciao
toralf
toralf
Re: AutoXYWH() - Move control automatically when GUI resized
thanks!!!!!!!!!!!!!!!!
-
- Posts: 58
- Joined: 18 Feb 2015, 15:06
Re: AutoXYWH() - Move control automatically when GUI resized
Does this function have problems with Named GUIs?
Something like
gui,mainGui:new
After I named the gui that way it stopped working.
Something like
gui,mainGui:new
After I named the gui that way it stopped working.
Re: AutoXYWH() - Move control automatically when GUI resized
I think it should not, but could you please post a short sample code that shows the problem?
ciao
toralf
toralf
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 144 guests