Hi,
I'm new to AHK and I have a question:
How can I do to simply center a button on a GUI?
I've search the internet but found nothing simple (or it's me )
There is some conditions:
-I don't know the size of the gui
-The GUI is not resizable
-The button have a fix width, height
Thanks in advance.
Simply center a button !?
Re: Simply center a button !?
You may use the GuiSize label:
Code: Select all
#NoEnv
Centered := False ; initial value = False / not centered
BtnW := 200 ; fixed button width
BtnH := 30 ; fixed button height
Random, GuiW, 300, 800 ; rendom GUI width
Random, GuiH, 100, 400 ; random GUI height
Gui, Add, Button, w%BtnW% h%BtnH% vCenteredBtn, Centered Button
Gui, Show, w%GuiW% h%GuiH%, Centered Button
Return
GuiClose:
ExitApp
GuiSize:
If (Centered = False) { ; the button hasn't been centered as yet
; Calculate the horizontally centered X-position
BtnX := (A_GuiWidth - BtnW) // 2
; Calculate the vertically centered Y-position
BtnY := (A_GuiHeight - BtnH) // 2
; Center the button
GuiControl, Move, CenteredBtn, x%BtnX% y%BtnY%
; Mark as centered
Centered := True
}
Return
Re: Simply center a button !?
Thanks...
I thought that the guisize was just for a resizable gui!!!
I still think that a build in command will be great!!!
I thought that the guisize was just for a resizable gui!!!
I still think that a build in command will be great!!!
- ankitkraken
- Posts: 84
- Joined: 01 Jun 2019, 08:47
- Location: India
Re: Simply center a button !?
Is there a simpler method available now?
moves the button after the previous element ends or before it begins. Is there no way to center the buttons relative to the previous elements?
Code: Select all
x+10
x-10
Who is online
Users browsing this forum: No registered users and 273 guests