Jump to content

Why does a control need to have double of it's coordinates removed from the GUI height and width to have equal spacing?


Recommended Posts

Hello, I am just getting started with making GUIs manually, by hand, without any tools/builders to assist me. I have discovered something strange: I am trying to fit a control (take an Edit control for example) with equal spacing on every side of the control... Something like this:

y0Tum70.png

I did something weird to make this happen, first I choose a coordinate for the X and Y for the Edit control, that is 4 in this GUI. I tried to remove 4 from the control's height and and width to make it space even at the right side and bottom of the GUI... but this happen when I tried that:

Q4jlRNy.png

As you can see, the Edit control is hugging the GUI frame at the bottom and right sides of the GUI... Very strange huh? I mean, it's a perfect 0 pixel gap! So I tried to double the coordinates and it worked. The GUI was evenly spaced on all side like in the first picture. This is my code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Local Const $eiGuiWidth = 580, $eiGuiHeight = 280
Local Const $eiCoord = 4
Global $g_hLogGUI = GUICreate("Test", $eiGuiWidth, $eiGuiHeight, Default, Default, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_WindowExit")
;GUICtrlCreateGroup("Test Group", $eiCoord, $eiCoord, $eiGuiWidth - ($eiCoord * 2), $eiGuiHeight - ($eiCoord * 2))
GUICtrlCreateEdit("", $eiCoord, $eiCoord, $eiGuiWidth - ($eiCoord * 2), $eiGuiHeight - ($eiCoord * 2))
GUISetState(@SW_SHOW, $g_hLogGUI) ; Make the GUI visible

While True
    Sleep(1000)
WEnd

Func GUI_WindowExit()
    Exit
EndFunc

You can adjust $eiCoord and the edit control will always be spaced evenly... I wonder why? any explanations? Thanks in Advance :)

P.S Sorry for the very descriptive title :sweating:

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

Sorry I seem to have misunderstood your question. I get a 4 pixel gap on all four sides of the edit using your code.

1 hour ago, TheDcoder said:

You can adjust $eiCoord and the edit control will always be spaced evenly... I wonder why?

Because the width and height are calculated accordingly : $eiGuiWidth - ($eiCoord * 2). You have to reduce the width of the edit for both the left and the right side ==> ($eiCoord * 2). Two gaps - right! :think:

Edited by czardas
Link to post
Share on other sites

@czardas I was expressing my thoughts in the form of that question, sorry if I was not clear enough. I know that it will always fit because $eiCoord is multiplied to 2, but why? why does it need the "gap" 2 times? That was my question :sweating:.

I have tried using the $WS_POPUP style and same result... minus the window border, so I think that is not the issue...

61meICE.png

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Local Const $eiGuiWidth = 580, $eiGuiHeight = 280
Local Const $eiCoord = 10
Global $g_hLogGUI = GUICreate("Test", $eiGuiWidth, $eiGuiHeight, Default, Default, $WS_POPUP)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_WindowExit")
;GUICtrlCreateGroup("Test Group", $eiCoord, $eiCoord, $eiGuiWidth - ($eiCoord * 2), $eiGuiHeight - ($eiCoord * 2))
GUICtrlCreateEdit("", $eiCoord, $eiCoord, $eiGuiWidth - ($eiCoord * 2), $eiGuiHeight - ($eiCoord * 2))
GUISetState(@SW_SHOW, $g_hLogGUI) ; Make the GUI visible

While True
    Sleep(1000)
WEnd

Func GUI_WindowExit()
    Exit
EndFunc

 

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...