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

Aligning text and objects

Expand Messages
  • John
    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
    Message 1 of 12 , Aug 2 10:32 AM
    • 0 Attachment
      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?

      Thanks,
    • William Lopez
      If you want text printed to the screen when using NOMAINWIN, you must use a textbox, graphicbox, statictext, or texteditor to contain the text. You will
      Message 2 of 12 , Aug 2 10:46 AM
      • 0 Attachment
        If you want text printed to the screen when using NOMAINWIN, you must use a textbox, graphicbox, statictext, or texteditor to "contain" the text. You will probably be printing a defined string. Pad the string front and rear with spaces until it is centered, then print the string to the container. NOTE BENE: different fonts will have different character widths. To truly center your text, you need to use a monospaced font, such as Courier New.

        Bill

        welopez@...

        To: libertybasic@yahoogroups.com
        From: jcoones@...
        Date: Tue, 2 Aug 2011 17:32:02 +0000
        Subject: [libertybasic] Aligning text and objects




























        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?



        Thanks,


















        [Non-text portions of this message have been removed]
      • Peter
        If using STATICTEXT then you can use STYLEBITS to center the text make the box the same width as the window and hey presto centered text. Try this Code
        Message 3 of 12 , Aug 2 10:58 AM
        • 0 Attachment
          If using STATICTEXT then you can use STYLEBITS to center the text make the
          box the same width as the window and hey presto centered text.
          Try this
          Code
          NOMAINWIN
          [Win.Size]
          WindowWidth = DisplayWidth : WindowHeight = DisplayHeight
          [Win.Controls]
          Stylebits #tw.stTitle, _SS_CENTER,0,0,0
          statictext #tw.stTitle, "Title Text Here", 0,25,WindowWidth,25
          [Win.Open]
          open "Test" for window as #tw
          #tw "trapclose [tw.quit]"
          [tw.loop]
          wait
          [tw.quit]
          close #tw
          end

          Peter
          ----- Original Message -----
          From: "William Lopez" <welopez@...>
          To: <libertybasic@yahoogroups.com>
          Sent: Tuesday, August 02, 2011 6:46 PM
          Subject: RE: [libertybasic] Aligning text and objects


          >
          > If you want text printed to the screen when using NOMAINWIN, you must use
          > a textbox, graphicbox, statictext, or texteditor to "contain" the text.
          > You will probably be printing a defined string. Pad the string front and
          > rear with spaces until it is centered, then print the string to the
          > container. NOTE BENE: different fonts will have different character
          > widths. To truly center your text, you need to use a monospaced font,
          > such as Courier New.
          >
          > Bill
          >
          > welopez@...
          >
          > To: libertybasic@yahoogroups.com
          > From: jcoones@...
          > Date: Tue, 2 Aug 2011 17:32:02 +0000
          > Subject: [libertybasic] Aligning text and objects
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          > 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?
          >
          >
          >
          > Thanks,
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >
          > ------------------------------------
          >
          > Yahoo! Groups Links
          >
          >
          >
          >
        • Stefan Pendl
          ... 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
          Message 4 of 12 , Aug 2 11:05 AM
          • 0 Attachment
            >
            > 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)

            nomainwin

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

            [quit]
            close #m
            end

            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
            http://stefanpendl.runbasichosting.com/

            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
          • Rod
            If you mean you are using the mainwin display then just add spaces to your text or use the Tab() function. Print tab(20); Hello Puts Hello twenty spaces in.
            Message 5 of 12 , Aug 2 11:51 AM
            • 0 Attachment
              If you mean you are using the mainwin display then just add spaces to your text or use the Tab() function.

              Print tab(20);"Hello"

              Puts Hello twenty spaces in.

              However, you have a fantastic learning experience ahead of you. The Mainwin which you play with how is actually the testing and development environment. You can use it just like an old console but the best bit is discovering the GUI windows and graphicboxes. You will have hours of fun and frustration :)

              --- In libertybasic@yahoogroups.com, "John" <jcoones@...> wrote:
              >
              > 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?
              >
              > Thanks,
              >
            • John
              Thank you for the help. Very much appreciated. I used to program in basic quite a bit back in the old DOS days using GFA Basic on an Atari. Also did some basic
              Message 6 of 12 , Aug 2 2:35 PM
              • 0 Attachment
                Thank you for the help. Very much appreciated.
                I used to program in basic quite a bit back in the old DOS days using GFA Basic on an Atari. Also did some basic stuff on a Commodore 64 but I am totally new at any windows type basic. I have to figure all this windows stuff out. I tried doing a very simple windows thing to just display some text as a learning project but while I got the window to appear including a 2 item menu that I set up, for some reason I could not get the text to display. I just used a simple Print statement but it would not display in the window. Lots to learn I guess. I'd like to find a place where I could get some sample code showing how to set up a window and get it to display something in the window. That way I might get a better understanding of how it works. Would you know of any sites that would have sample code snippets?

                Thanks again for you help.

                Cheers.


                --- In libertybasic@yahoogroups.com, "Rod" <rodbird@...> wrote:
                >
                > If you mean you are using the mainwin display then just add spaces to your text or use the Tab() function.
                >
                > Print tab(20);"Hello"
                >
                > Puts Hello twenty spaces in.
                >
                > However, you have a fantastic learning experience ahead of you. The Mainwin which you play with how is actually the testing and development environment. You can use it just like an old console but the best bit is discovering the GUI windows and graphicboxes. You will have hours of fun and frustration :)
                >
                > --- In libertybasic@yahoogroups.com, "John" <jcoones@> wrote:
                > >
                > > 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?
                > >
                > > Thanks,
                > >
                >
              • Gary Passmore
                In graphic windows, the command stringwidth? string$ width  is handy for centering text, as the font needn t be fixed width. Simply position the pen at
                Message 7 of 12 , Aug 2 3:33 PM
                • 0 Attachment
                  In graphic windows, the command "stringwidth? string$ width" is handy for centering text, as the font needn't be fixed width.
                  Simply position the pen at center-width/2 and print.

                  ...from the world according to GaRPMorE
                • paradisejb
                  ... John, A user cannot interact directly with the window in a graphical user interface (GUI), like he can when using the MAINWIN. (The mainwin is text based,
                  Message 8 of 12 , Aug 2 5:14 PM
                  • 0 Attachment
                    --- In libertybasic@yahoogroups.com, "John" <jcoones@...> wrote:
                    >
                    > ... I tried doing a very simple windows thing to just display some text as a learning project but while I got the window to appear including a 2 item menu that I set up, for some reason I could not get the text to display. I just used a simple Print statement but it would not display in the window. Lots to learn I guess. I'd like to find a place where I could get some sample code showing how to set up a window and get it to display something in the window. ...
                    >
                    John,

                    A user cannot interact directly with the window in a graphical user interface (GUI), like he can when using the MAINWIN. (The mainwin is text based, like Notepad).

                    To interact with GUI based programs, the user interacts with "controls". You cannot print directly to a window, you must print to a control. For text display you have two basic controls: statictext and textboxes.

                    You'll find the Windows GUI programming to be exciting and challenging. It's all very manageable when taken a step at a time. If your version of LB is late enough, you may have the Lesson Browser included. With it, you can run a Tutorial Lesson series. To check if you have the Lesson Browser, look under the Help menu for an item called "Liberty BASIC Tutorial". That would be a good place to start.

                    Hope it helps.
                  • John
                    Thank you very much for your reply. Very helpful and appreciated. Cheers.
                    Message 9 of 12 , Aug 2 11:42 PM
                    • 0 Attachment
                      Thank you very much for your reply. Very helpful and appreciated.

                      Cheers.

                      ===================================================================

                      --- In libertybasic@yahoogroups.com, William Lopez <welopez@...> wrote:
                      >
                      >
                      > If you want text printed to the screen when using NOMAINWIN, you must use a textbox, graphicbox, statictext, or texteditor to "contain" the text. You will probably be printing a defined string. Pad the string front and rear with spaces until it is centered, then print the string to the container. NOTE BENE: different fonts will have different character widths. To truly center your text, you need to use a monospaced font, such as Courier New.
                      >
                      > Bill
                      >
                      > welopez@...
                      >
                      > To: libertybasic@yahoogroups.com
                      > From: jcoones@...
                      > Date: Tue, 2 Aug 2011 17:32:02 +0000
                      > Subject: [libertybasic] Aligning text and objects
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      > 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?
                      >
                      >
                      >
                      > Thanks,
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      >
                      > [Non-text portions of this message have been removed]
                      >
                    • Stefan Pendl
                      ... This statement is incorrect, since there is no need to use a fixed width font, if you use the center style. ... I doubt that centering in the graphics box
                      Message 10 of 12 , Aug 3 1:49 AM
                      • 0 Attachment
                        >
                        > '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)

                        nomainwin
                        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
                        else
                        xPos = (170 - txtWidth)/2
                        end if

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

                        [quit]
                        close #m
                        end

                        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
                        http://stefanpendl.runbasichosting.com/

                        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
                      • Stefan Pendl
                        ... Yes, that s the sizing-frame. It would be great to define a window by its client area, since that is what can be used. We will get a perfect world when
                        Message 11 of 12 , Aug 3 9:16 AM
                        • 0 Attachment
                          >
                          > BorderWidth? I mistook that as margin. The correct term may
                          > be FrameWidth. I used "window_nf" which has no frame (border).
                          >

                          Yes, that's the sizing-frame.

                          It would be great to define a window by its client area, since that is what can be used.

                          We will get a perfect world when time has come ;-)


                          ---
                          Stefan Pendl
                          http://stefanpendl.runbasichosting.com/

                          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
                        • Stefan Pendl
                          ... There is an API function to get the window size based on the client area at http://msdn.microsoft.com/en-us/library/ms632665%28VS.85%29.aspx So you feed
                          Message 12 of 12 , Aug 3 9:27 AM
                          • 0 Attachment
                            >
                            > >
                            > > BorderWidth? I mistook that as margin. The correct term may
                            > > be FrameWidth. I used "window_nf" which has no frame (border).
                            > >
                            >
                            > Yes, that's the sizing-frame.
                            >
                            > It would be great to define a window by its client area,
                            > since that is what can be used.
                            >

                            There is an API function to get the window size based on the client area at
                            http://msdn.microsoft.com/en-us/library/ms632665%28VS.85%29.aspx

                            So you feed the function the expected client area size and it returns the window size needed, taking into account the style of the
                            window.
                            We would now need the styles of the window types available in LB to create a function, that would calculate the window size based on
                            the expected client area size and the LB window type.


                            ---
                            Stefan Pendl
                            http://stefanpendl.runbasichosting.com/

                            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
                          Your message has been successfully submitted and would be delivered to recipients shortly.