Results 1 to 4 of 4

Thread: Alignment on Printer.print

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2013
    Location
    Brazil
    Posts
    28

    Alignment on Printer.print

    Hi guys!

    after many problems with data reports, crystal reports and things like that, i'm decided to use the Printer.print.

    I made a simple class, that class receive a ListView Control and after i export the data of the listview to some array. Finally i can get the columheader titles, and the other records to print through the printer.print.

    After got all the listview lines, i print them column by column, and i'm looking for some way to auto generate the spaces between columns. This way, that class could receive only a listview control and auto generate a report.

    any idea to auto generate column spaces on my document made by Printer.print?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Alignment on Printer.print

    Code:
    printer.currentX = col(n)
    where col is an array of the positions for each column, before printing each column data
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2013
    Location
    Brazil
    Posts
    28

    Re: Alignment on Printer.print

    But i need to give all the spaces with some dinamic way....

    i found a class on the internet, and this class solve the most part of the problem...

    now, i can print formated collumns... but, when i've large list-views i need to auto change the printer.orientation to landscape.

    any idea?

    Code:


    Public Sub PrintListView(lvw As ListView)
    Const MARGIN = 60
    Const COL_MARGIN = 240

    Dim ymin As Single
    Dim ymax As Single
    Dim xmin As Single
    Dim xmax As Single
    Dim num_cols As Integer
    Dim column_header As ColumnHeader
    Dim list_item As ListItem
    Dim i As Integer
    Dim num_subitems As Integer
    Dim col_wid() As Single
    Dim X As Single
    Dim Y As Single
    Dim line_hgt As Single

    xmin = Printer.CurrentX
    ymin = Printer.Currenty

    ' ******************
    ' Get column widths.
    num_cols = lvw.ColumnHeaders.Count
    ReDim col_wid(1 To num_cols)

    ' Check the column headers.
    For i = 1 To num_cols
    col_wid(i) = _
    Printer.TextWidth(lvw.ColumnHeaders(i).Text)
    Next i

    ' Check the items.
    num_subitems = num_cols - 1
    For Each list_item In lvw.ListItems
    ' Check the item.
    If col_wid(1) < Printer.TextWidth(list_item.Text) _
    Then _
    col_wid(1) = Printer.TextWidth(list_item.Text)

    ' Check the subitems.
    For i = 1 To num_subitems
    If col_wid(i + 1) < _
    Printer.TextWidth(list_item.SubItems(i)) _
    Then _
    col_wid(i + 1) = _
    Printer.TextWidth(list_item.SubItems(i))
    Next i
    Next list_item

    ' Add a column margin.
    For i = 1 To num_cols
    col_wid(i) = col_wid(i) + COL_MARGIN
    Next i

    ' *************************
    ' Print the column headers.

    Printer.Currenty = ymin + MARGIN
    Printer.CurrentX = xmin + MARGIN
    X = xmin + MARGIN
    For i = 1 To num_cols


    Printer.CurrentX = X
    Printer.Print FittedText( _
    lvw.ColumnHeaders(i).Text, col_wid(i));
    X = X + col_wid(i)
    Next i
    xmax = X + MARGIN

    Printer.Print
    line_hgt = Printer.TextHeight("X")
    Y = Printer.Currenty + line_hgt / 2
    Printer.Line (xmin, Y)-(xmax, Y)
    Y = Y + line_hgt / 2

    ' Print the rows.
    num_subitems = num_cols - 1
    For Each list_item In lvw.ListItems
    X = xmin + MARGIN

    ' Print the item.
    Printer.CurrentX = X
    Printer.Currenty = Y
    Printer.Print FittedText( _
    list_item.Text, col_wid(1));
    X = X + col_wid(1)

    ' Print the subitems.
    For i = 1 To num_subitems
    Printer.CurrentX = X
    Printer.Print FittedText( _
    list_item.SubItems(i), col_wid(i + 1));
    X = X + col_wid(i + 1)
    Next i

    Y = Y + line_hgt * 1.5
    Next list_item
    ymax = Y

    ' Draw lines around it all.
    Printer.Line (xmin, ymin)-(xmax, ymax), , B

    X = xmin + MARGIN / 2
    For i = 1 To num_cols - 1
    X = X + col_wid(i)
    Printer.Line (X, ymin)-(X, ymax)
    Next i
    End Sub

    ' Return as much text as will fit in this width.
    Private Function FittedText(ByVal txt As String, ByVal wid _
    As Single) As String
    Do While Printer.TextWidth(txt) > wid
    txt = Left$(txt, Len(txt) - 1)
    Loop
    FittedText = txt
    End Function
    when i try to change this part of the code:

    ' Print the column headers.

    Printer.Currenty = ymin + MARGIN
    Printer.CurrentX = xmin + MARGIN
    X = xmin + MARGIN
    For i = 1 To num_cols
    If X > Printer.ScaleWidth - 500 Then
    Printer.Orientation = 1
    Else
    Printer.Orientation = 2
    End If
    Printer.CurrentX = X
    Printer.Print FittedText( _
    lvw.ColumnHeaders(i).Text, col_wid(i));
    X = X + col_wid(i)
    Next i
    xmax = X + MARGIN
    i receive this message:

    "Wrong number of arguments or invalid property assigment" in this line:
    Printer.Line (xmin, Y)-(xmax, Y)
    Last edited by Rumblefish; Jun 19th, 2013 at 08:37 AM.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2013
    Location
    Brazil
    Posts
    28

    Re: Alignment on Printer.print

    Problem solved... i put the Printer.Orientation before the class.

    But now... ive a problem with pages.

    My first page have multiple lines, but for each page after the first... only 1 line is printed.

    O.o'

    i can't understand...

    any idea?

Tags for this Thread

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