How do I center the image/button in gui?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

How do I center the image/button in gui?

23 Mar 2018, 01:20

Uhm lol.

Code: Select all

p::
Gui, New, +AlwaysOnTop +Border, ALERT
Gui, Add, Picture,, Seel.png
Gui, Font, S15 
Gui, Add, Text, +center ,  Hello darkness my old friend
Gui, Font, S20
Gui, Add, Button, Default, OK
Gui, Show, Center
return
I want the image and the button to be at the center of the gui. How.
I am your average ahk newbie. Just.. a tat more cute. ;)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How do I center the image/button in gui?

23 Mar 2018, 01:34

:arrow: Position

x := GuiWidth/2+ControlWidth/2 ; these are no valid AHKvars
y := GuiHeight/2+ControlHeight/2 ; these are no valid AHKvars
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: How do I center the image/button in gui?

23 Mar 2018, 02:03

BoBo wrote::arrow: Position

x := GuiWidth/2+ControlWidth/2 ; these are no valid AHKvars
y := GuiHeight/2+ControlHeight/2 ; these are no valid AHKvars
Thanks anyway. I wanted a resizable gui where the controls always stayed in the center I thought there was an easier way out.
But how would you do that? I don't want the size of the controls to change.
I am your average ahk newbie. Just.. a tat more cute. ;)
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: How do I center the image/button in gui?

23 Mar 2018, 08:44

Try this:

Code: Select all

Gui, +hwndGUI +AlwaysOnTop +Resize
Gui, Margin,0,0
Gui, Add, button, w100 h50 hwndBTN, Button
Gui, show, w150 h100
return

GuiSize:
	gui, Submit, NoHide
	WinGetPos,x,y,w,h, % "Ahk_id" GUI
	ControlGetPos,cx,cy,cw,ch,, % "Ahk_id" BTN
	SysGet, cyborder, 8
	SysGet, sizeframe, 33
	SysGet, title, 31
	GuiControl, move, % BTN, % "x" w/2-(cw/2+sizeframe) "y" h/2-(ch/2+title-cyborder)
return
It's just an example for a single button but I'm sure you can accomodate it for the image too.
Cheers.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mcd, MSN [Bot], NinjoOnline and 281 guests