Author |
Topic: Centering a window (Read 182 times) |
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Centering a window
« Thread started on: Apr 5th, 2017, 5:30pm » |
|
I'm having trouble centering a wide window. Other, narrower, windows center nicely using this:
Code:
UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
I also tried various combinations of UpperLeftX and UpperLeftX with no luck - the window opens too far to the right - partly off-screen Is there some limit to the width of a window that can be centered? I guess I would settle for all of the window being visible without having to manually drag it.
r.m.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: Centering a window
« Reply #1 on: Apr 5th, 2017, 8:09pm » |
|
What is "wide" window? Up to DisplayWidth it centers OK If you ask for more, it limits itself to DisplayWidth in JB it positions partly off- screen (left-ways) in LBB it positions from 0 Now, from 0 and DisplayWidth - again centered
Or so it works to me. Code:WindowWidth = 1.5*DisplayWidth 'gange this number, 0.9 1.0 1.1 ...
UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
print UpperLeftX
UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
'nomainwin
open "test" for window as #main
#main "trapclose [quit]"
wait
[quit]
close #main
end
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Re: Centering a window
« Reply #2 on: Apr 5th, 2017, 8:58pm » |
|
If I change the window type from "dialog_modal" to "window" my program 'works'. If I change the window type in your code from "window" to dialog_modal, it does not center, but does keep all the window in view.
r.m.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Centering a window
« Reply #3 on: Apr 5th, 2017, 9:17pm » |
|
on Apr 5th, 2017, 8:58pm, Alincon wrote:If I change the window type in your code from "window" to dialog_modal, it does not center, but does keep all the window in view. |
|
To center a dialog window you must use a style bit:
Code: WindowWidth = 300
WindowHeight = 300
stylebits #w, _DS_CENTER, 0, 0, 0
open "test" for dialog_modal as #w
wait Richard.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: Centering a window
« Reply #4 on: Apr 5th, 2017, 9:22pm » |
|
dialog modal is different beast it is positioned based on parent window. So uppertLeftX doesn't supposed to work (if only you position parent window first I think)
But there are stylebits. Search on LB forum returned this: Topic: Stylebit not working!
so Code:WindowWidth = 0.9*DisplayWidth 'gange this number, 0.9 1.0 1.1 ...
UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
print UpperLeftX
UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
'nomainwin
stylebits #main, _DS_CENTER, _WS_SYSMENU, 0, 0
open "test" for dialog_modal as #main
#main "trapclose [quit]"
wait
[quit]
close #main
end
EDIT while I search Richard just *knows* ;)
|
« Last Edit: Apr 5th, 2017, 9:23pm by tsh73 » |
Logged
|
|
|
|
|