Jump to content
TheDcoder

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

TheDcoder

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:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
czardas

Its a border style. You can get rid of it by changing the style. Look at control/win styles - particularly extended styles.

Edited by czardas

Share this post


Link to post
Share on other sites
czardas

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

Share this post


Link to post
Share on other sites
TheDcoder

@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

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
czardas

It's because you are referencing the width of the GUI to set the width of the Edit control. The horizontal dimensions are as follows:

<=4=>| EDIT |<=4=>
<===GUI Width ===>

C'mon, get with it. :P

Edited by czardas
  • Like 1

Share this post


Link to post
Share on other sites
TheDcoder
28 minutes ago, czardas said:

C'mon, get with it. :P

Wikip-facepalm.jpg

Thanks for the ASCII Drawing :thumbsup:

P.S I am not the one in the facepalm photo

  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


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

×