Announcement

Collapse
No announcement yet.

Format$, Rset and right justify

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Format$, Rset and right justify

    I'm using TextOut to write the scale values to a graphic shown below. I want the numbers on the vertial axis to be right justified, specifically the 0 at the origin to be in line with the last 0 of 10,000. The numbers an the scale graphic are on the same dc. I've played with this far to long and can't get it working - my current code is
    TempText = FORMAT$(BigTickCount * 1000, "#####,")
    RSET TempText = TempText USING " "
    TextOut hMemVScaleDC, 5, (VForCount - 5), TempText, BYVAL LEN(TempText)
    Click image for larger version

Name:	PlotForm.jpg
Views:	87
Size:	96.1 KB
ID:	780338

  • #2
    Tried RSET$ vs. RSET?
    Dale

    Comment


    • #3
      Can try using SetTextAlign(hMemVScaleDC, %TA_RIGHT) before TextOut, but you'll need test out a new reference point where right side of text shall begin.

      Comment


      • #4
        If I do
        Local TempText as ASCIIZ * 7
        .
        .
        TempText = Format$(BigTickCount * 1000, "#####,")
        TempText = Rset$(TempText, 6)
        TextOut(hMemVScaleDC, 5, (VForCount - 5), TempText, 7)
        it moves the 0 over a couple of chars but not all the way under the 0 in 10,000.

        I wonder if this has something to do with the default SetTextAlign? I'm letting it default currently.

        Comment


        • #5
          Is there a problem? Following example draws text i right-aligned "column". Format$ and RSet not needed.
          Code:
          #COMPILE EXE
          #DIM ALL
          #INCLUDE "WIN32API.INC"
          
          '====================================================================
          FUNCTION PBMAIN () AS LONG
            LOCAL hDlg AS DWORD
          
            DIALOG NEW 0, "SetTextAlign",,, 120, 70, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
            '------------------------------------------------------------------
            DIALOG SHOW MODAL hDlg CALL DlgProc
          
          END FUNCTION
          
          
          '====================================================================
          CALLBACK FUNCTION DlgProc() AS LONG
            SELECT CASE AS LONG CB.MSG
            CASE %WM_PAINT
                LOCAL hDC AS DWORD, zTxt AS ASCIIZ * 10
                hDC  = GetDc(CB.HNDL) ' CB.WPARAM
                SetBkColor(hDC, GetSysColor(%COLOR_3DFACE))
                SetTextAlign(hDC, %TA_RIGHT)
                zTxt = "10,000"
                TextOut(hDC, 50, 5, zTxt, LEN(zTxt)) 'Draw text
                zTxt = "5,000"
                TextOut(hDC, 50, 20, zTxt, LEN(zTxt)) 'Draw text
                zTxt = "0"
                TextOut(hDC, 50, 35, zTxt, LEN(zTxt)) 'Draw text
                ReleaseDc(CB.HNDL, hDC)
          
            END SELECT
          END FUNCTION
          Click image for larger version  Name:	SetTextAlign.jpg Views:	0 Size:	5.1 KB ID:	780346

          Comment


          • #6

            fixed width font? Spaces are a lot narrower than "0" in proportional font

            TempText = RSET$(DEC$(BigTickCount * 1000), 6)
            TextOut(hMemVScaleDC, 5, (VForCount - 5), TempText, 6) 'does not hat to be Z string because next para is number of characters used. even if it is Z, only 6 characters are used.

            Cheers,

            added - or what Borje did while I was working on that.
            Dale

            Comment


            • #7
              Thanks for your efforts guys
              @Borje I can't use SetTextAlign cause I'm drawing the scale on the same dc and it gets overwritten.
              @Dale I think you nailed it, I'm usingMicrosoft San Serif which is prop.

              Comment


              • #8
                Should not happen if you set x correctly before (to the left of) scale, since you can use TextOut with standard %TA_LEFT flag set for TextAlign without problem. With %TA_RIGHT flag, text is right-aligned at x - like screen shot shows.

                > @Borje I can't use SetTextAlign cause I'm drawing the scale on the same dc and it gets overwritten.

                Click image for larger version  Name:	SetTextAlign2.jpg Views:	0 Size:	5.1 KB ID:	780363
                Code:
                #COMPILE EXE
                #DIM ALL
                #INCLUDE "WIN32API.INC"
                
                '====================================================================
                FUNCTION PBMAIN () AS LONG
                  LOCAL hDlg AS DWORD
                
                  DIALOG NEW 0, "SetTextAlign",,, 120, 60, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
                  '------------------------------------------------------------------
                  DIALOG SHOW MODAL hDlg CALL DlgProc
                
                END FUNCTION
                
                
                '====================================================================
                CALLBACK FUNCTION DlgProc() AS LONG
                  SELECT CASE AS LONG CB.MSG
                  CASE %WM_PAINT
                      LOCAL hDC AS DWORD, zTxt AS ASCIIZ * 10
                      hDC  = GetDc(CB.HNDL)
                        SetBkColor(hDC, GetSysColor(%COLOR_3DFACE))
                        SetTextAlign(hDC, %TA_RIGHT)
                        zTxt = "10,000"
                        TextOut(hDC, 50,  5, zTxt, LEN(zTxt)) 'Draw text
                        zTxt = "5,000"
                        TextOut(hDC, 50, 20, zTxt, LEN(zTxt))
                        zTxt = "0"
                        TextOut(hDC, 50, 35, zTxt, LEN(zTxt))
                
                        MoveToEx hDC, 63,  8, "" : LineTo hDC, 63, 43
                        MoveToEx hDC, 55, 12, "" : LineTo hDC, 63, 12
                        MoveToEx hDC, 55, 27, "" : LineTo hDC, 63, 27
                        MoveToEx hDC, 55, 42, "" : LineTo hDC, 63, 42
                      ReleaseDc(CB.HNDL, hDC)
                
                  END SELECT
                END FUNCTION

                Comment


                • #9
                  Oops, see what youmean, sorry this stuff is all very new to me.

                  Comment


                  • #10
                    Thank you Borje, how do you print this screen to a printer?
                    How to use XPRINT command and plot this graphics to a printer ?

                    Comment


                    • #11
                      I'm sure this obvious to everyone (except me obviously) but if you SetTextAlighn to %TA_RIGHT the x parameter is now the right hand side.

                      Comment

                      Working...
                      X