LB Booster
Programming >> Liberty BASIC language >> Centering a window
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1491413452

Centering a window
Post by Alincon 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.

Re: Centering a window
Post by tsh73 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 


Re: Centering a window
Post by Alincon 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.
Re: Centering a window
Post by Richard Russell 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.

Re: Centering a window
Post by tsh73 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* ;)