Loading ...
Sorry, an error occurred while loading the content.

43558RE: [libertybasic] Aligning text and objects

Expand Messages
  • Stefan Pendl
    Aug 3, 2011
      > 'without graphics (must use fixed width font)
      > statictext #w.txt, txt$, 0, 50, WindowWidth, 40

      This statement is incorrect, since there is no need to use a fixed width font, if you use the center style.

      > 'with graphics (looks more precisely centered, can use any font)
      > graphicbox #w.gbx, 0, 100, WindowWidth, 40

      I doubt that centering in the graphics box is better, since both controls need to take the window border into account, which must be
      subtracted from the window width to get the width of the client area, which is what the user sees.

      The below example shows, that you are misaligned, if you do not take the window border into account.
      Sure things would be easier, if LB would offer the size of the client area as variables, but this must be done manually.

      '---code start (watch for line wraps)

      txt$="Welcome to Liberty Basic"

      BorderWidth = GetBorderWidth() * 2

      WindowWidth = 170 + BorderWidth
      WindowHeight = 150

      statictext #m.txt, txt$, 0, 10, 170, 20
      stylebits #m.txt, _SS_CENTER, 0, 0, 0

      graphicbox #m.gbx1, 0, 40, 170, 30
      stylebits #m.gbx1, 0, _WS_BORDER, 0, 0

      graphicbox #m.gbx2, 0, 80, 170, 30
      stylebits #m.gbx2, 0, _WS_BORDER, 0, 0

      open "Test" for window as #m
      #m "trapclose [quit]"
      #m "font times_new_roman 12"

      for i = 1 to 2
      Handle$ = "#m.gbx"; i

      #Handle$ "font times_new_roman 12"
      #Handle$ "down; fill buttonface; backcolor buttonface"
      #Handle$ "stringwidth? txt$ txtWidth"

      if i = 1 then
      xPos = (WindowWidth-txtWidth)/2
      xPos = (170 - txtWidth)/2
      end if

      #Handle$ "place "; xPos; " 0"
      #Handle$ "\\"; txt$
      #Handle$ "flush"

      close #m

      function GetBorderWidth()
      ' get the width of the window border in pixels
      nIndex = 32 ' SM_CXFRAME

      calldll #user32, "GetSystemMetrics",_
      nIndex as long,_
      GetBorderWidth as long
      end function

      '---code end

      Stefan Pendl

      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
    • Show all 12 messages in this topic