Results 1 to 7 of 7

Thread: Print MSFlexgrid Aligned [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Print MSFlexgrid Aligned [RESOLVED]

    Im having a spot of bother printing my flexgrid.
    I use the following code (copied from here somewhere)
    VB Code:
    1. Dim strRowText As String
    2.         With ResGrid
    3.             For i = 0 To .Rows - 1
    4.                 strRowText = ""
    5.                 strRowText = strRowText & .TextMatrix(i, 0) & vbTab & vbTab
    6.                 For j = 1 To .Cols - 1
    7.                     strRowText = strRowText & .TextMatrix(i, j) & vbTab
    8.                 Next j
    9.                 Printer.Print vbTab & vbTab & strRowText
    10.             Next i
    11.         End With
    This prints out a nice grid until one of the row headers is too long.


    How can I align this properly?
    Attached Images Attached Images  

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    for that you need to either print each cell individually (using the printers CurrentX and CurrentY to specify the current position), or make the text in the left hand column the same printed width by adding spaces (which I'm afraid isn't accurate - as all character sizes vary)

  3. #3
    Addicted Member Abilio's Avatar
    Join Date
    May 2003
    Location
    Aveiro - Portugal
    Posts
    222
    Printer.CurrentX = 115 - Printer.TextWidth("1.114,55")
    Printer.CurrentY = 50
    Printer.Print "1.114,55"

    prints 1.114,55 from right to left starting at point 115

  4. #4

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    CurrentX doesn't seem to work because I want to set it
    differently for each word on the same line.
    I was under the impression that Printer.Print couldn't be
    used to print part of a line at a time

    The answer appears to be in this post.
    http://www.vbforums.com/showthread.p...threadid=61145
    Using commas for separate print zones or Tab(n) to separate.
    I'm having a mind block on how to implement it though!

  5. #5

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    I decided on a workaround that was simpler to implement.
    I put in an If statement to see if the header was longer than a Tab.
    VB Code:
    1. Dim strRowText As String
    2.  
    3.         With ResGrid
    4.             For i = 0 To .Rows - 1
    5.                 strRowText = ""
    6.                 'Row header. ie device name
    7.                 If TextWidth(ResGrid.TextMatrix(i, 0)) < 600 Then
    8.                     strRowText = strRowText & .TextMatrix(i, 0) & vbTab & vbTab
    9.                 Else
    10.                     strRowText = strRowText & .TextMatrix(i, 0) & vbTab
    11.                 End If
    12.                 'Numbers in table
    13.                 For j = 1 To .Cols - 1
    14.                     strRowText = strRowText & .TextMatrix(i, j) & vbTab
    15.                 Next j
    16.                 Printer.Print vbTab & vbTab & strRowText
    17.             Next i
    18.         End With
    Im fairly certain that it will work in this application as the length of the header is restricted elsewhere.
    Not as robust as I would like though.

  6. #6
    Addicted Member Abilio's Avatar
    Join Date
    May 2003
    Location
    Aveiro - Portugal
    Posts
    222
    Sub CabeçalhoMapa(Grelha As MSFlexGrid)
    Dim Abcissa As Integer
    Abcissa = 15
    Printer.ScaleMode = vbMillimeters

    Printer.Line (1, 1 + Abcissa)-(Printer.ScaleWidth, 7 + Abcissa), vbBlue, BF
    With Printer
    .FontSize = 14
    .FontBold = True
    .ForeColor = vbBlue
    .CurrentX = 1
    .CurrentY = 1
    Printer.Print "CDCA - NATAÇÃO"
    .ForeColor = vbWhite
    .FontSize = 10
    .CurrentX = 2
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 0)
    .CurrentX = 70
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 1)
    .CurrentX = 115 - Printer.TextWidth(Grelha.TextMatrix(0, 2))
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 2)
    .CurrentX = 135 - Printer.TextWidth(Grelha.TextMatrix(0, 3))
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 3)
    .CurrentX = 155 - Printer.TextWidth(Grelha.TextMatrix(0, 4))
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 4)
    .CurrentX = 175 - Printer.TextWidth(Grelha.TextMatrix(0, 5))
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 5)
    .CurrentX = 195 - Printer.TextWidth(Grelha.TextMatrix(0, 6))
    .CurrentY = 1 + Abcissa
    SetBkMode Printer.hdc, TRANSPARENT
    Printer.Print Grelha.TextMatrix(0, 6)
    End With


    End Sub

    As you can see, CurrentX can be assigned more then once for a single line.

    Best regards

  7. #7

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Suddenly it all becomes clear!

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width