43551RE: [libertybasic] Aligning text and objects
- Aug 2, 2011
>So you are using a GUI of type window for instance.
> I purchased LB some time ago but never really got to use it
> much. I have since retired and now have time to learn how it works.
> One question I have, which may seem simple, is:
> when using NOMAINWIN, how do you position text in the display
> area? In other words, if I have some text that I want
> centered horizontally on the screen, what is the best way to do this?
For STATICTEXT you can use the STYLEBITS command and add the regular style _SS_CENTER.
This will center the text in the area defined for the static text control.
To center the text in respect to the window width, you need to make the static text control as wide as the internal area.
'---code start (watch for line wraps)
BorderWidth = GetBorderWidth() * 2
statictext #m.txt, "I am centered!", 0, 10, WindowWidth - BorderWidth, 20
stylebits #m.txt, _SS_CENTER, 0, 0, 0
open "Test" for window as #m
#m "trapclose [quit]"
' get the width of the window border in pixels
nIndex = 32 ' SM_CXFRAME
calldll #user32, "GetSystemMetrics",_
nIndex as long,_
GetBorderWidth as long
Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe
Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/
Books at http://www.lulu.com/ and http://www.amazon.com/
Alyce Watson ... APIs for Liberty BASIC
Carl Gundel .... Beginning Programming with Liberty BASIC
Windows 7 Home Premium 64-bit SP1
AMD Turion X2 RM-70 2GHz, 4GB RAM
- << Previous post in topic Next post in topic >>