Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21090

Can i use Print preview before printing with Printer.print?

$
0
0
can i do something like this?

any idea?

i've more 1 problem...

when i print something, the first page had multiple lines, but all the rest of the print had only 1 line per page.

How can i solve this?

CODE
Quote:

Dim total As Long
Dim posicaocab As Integer
Dim poeespaco As String
Dim margem As Long
Dim mrg As Long



Public Sub PrintListView(lvw As ListView)
Dim MARGIN As Long
Dim COL_MARGIN As Long

If total <> 0 Then
COL_MARGIN = margem
MARGIN = total
End If

If mrg <> 0 Then
MARGIN = mrg
End If


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.CurrentY = posicaocab
Printer.CurrentX = xmin + MARGIN
x = xmin + MARGIN
For i = 1 To num_cols


Printer.CurrentX = x
Dim poeespaco As String

For EX = 1 To Len(lvw.ColumnHeaders(i).Text)
poeespaco = lvw.ColumnHeaders(i).Text
If Mid$(poeespaco, EX, 1) = " " Then
Mid$(poeespaco, EX, 1) = " " = Mid$(poeespaco, EX, 1) & vbCrLf
End If
Next EX

Printer.Print FittedText( _
poeespaco, 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.
If Printer.CurrentY > Printer.Height - 200 Then
Printer.NewPage
End If
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

Public Sub ImprimeTextoAlinhado(Texto As String, Alignment As String)
Select Case Alignment
Case "Centro"
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Texto)) / 2
Case "Esquerda"
Printer.CurrentX = 0
Case "Direita"
Printer.CurrentX = Printer.ScaleWidth - Printer.TextWidth(Texto)
End Select
Printer.Print Texto
'Printer.EndDoc
End Sub
Public Sub cabecalho(ByVal list As ListView, ByVal Titulo As String, ByVal loja As Variant, ByVal versao As String)
total = 0
Dim i As Long
Dim soma As Long
For i = 1 To list.ColumnHeaders.Count
If soma < list.ColumnHeaders(i).Width Then
soma = list.ColumnHeaders(i).Width
End If
Next i

soma = soma * list.ColumnHeaders.Count

If soma > 17000 Then
Printer.Orientation = 2
'Printer.CurrentX = MX
'Printer.Currenty = MY




Dim mat As Variant
ReDim mat(list.ColumnHeaders.Count)




For Each list_item In list.ListItems

' Check the item.
If mat(1) < Printer.TextWidth(list_item.Text) _
Then _
mat(1) = Printer.TextWidth(list_item.Text)

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


For i = 1 To UBound(mat, 1)
total = total + mat(i)
Next i

mrg = (Printer.ScaleWidth - total) / 2



Else
Printer.Orientation = 1
ReDim mat(list.ColumnHeaders.Count)




For Each list_item In list.ListItems

' Check the item.
If mat(1) < Printer.TextWidth(list_item.Text) _
Then _
mat(1) = Printer.TextWidth(list_item.Text)

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


For i = 1 To UBound(mat, 1)
total = total + mat(i)
Next i

total = Printer.ScaleWidth - total
total = total / UBound(mat, 1)


Printer.CurrentX = MX
Printer.CurrentY = MY
End If


Printer.CurrentY = MY
Printer.FontBold = True
Printer.FontSize = 14
Call ImprimeTextoAlinhado(Titulo, "Centro")
Printer.Print
Printer.FontSize = 12
Dim strcab As String
strcab = "Loja: " & loja & " Data:" & Format(Now, "dd/mm/yyyy") & " Versao:" & versao
Call ImprimeTextoAlinhado(strcab, "Centro")
Printer.Print
Printer.FontBold = False

Printer.FontSize = 8

posicaocab = Printer.CurrentY + 20

End Sub

Viewing all articles
Browse latest Browse all 21090

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>