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

43551RE: [libertybasic] Aligning text and objects

Expand Messages
  • Stefan Pendl
    Aug 2, 2011
      > 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?

      So you are using a GUI of type window for instance.

      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]"

      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