HI,
I WORK WITH PRINTDOCUMENT CONTROL AND I WANT TO PRINT MORE THAN 1 PAGES. I PUT IN PrintDocument1_ PrintPage CODE :
BUT WHEN I PUSH PRINT BUTTON PRINTS ME ONLY THE SECOND PAGE.
CAN ANYONE HELP ME ?
THANKS
I WORK WITH PRINTDOCUMENT CONTROL AND I WANT TO PRINT MORE THAN 1 PAGES. I PUT IN PrintDocument1_ PrintPage CODE :
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim Lm As Integer
Dim Rm, dgvRows As Integer
Dim HasMorePages As Boolean = True
Static pagenum As Integer
With Form9.dgv2
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
fmt.LineAlignment = StringAlignment.Center
fmt.Trimming = StringTrimming.EllipsisCharacter
Dim y As Single = e.MarginBounds.Top 'ΕΧΕΙ ΤΙΜΗ 100
newPage = True
Do While mRow < Form9.dgv2.RowCount
Dim row As DataGridViewRow = Form9.dgv2.Rows(mRow)
Dim x As Single = e.MarginBounds.Left - 95
Dim h As Single = 0
For Each cell As DataGridViewCell In row.Cells
Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
If (newPage) Then
PrintFont = New Font("arial black", 7)
e.Graphics.DrawString(Form9.dgv2.Columns(cell.ColumnIndex).HeaderText, PrintFont, Brushes.Black, rc, fmt)
Else e.Graphics.DrawString(Form9.dgv2.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), Form9.dgv2.Font, Brushes.Black, rc, fmt)
End If
x += rc.Width
h = Math.Max(h, rc.Height)
Next
newPage = False
y += h
mRow += 1
If y + h > e.MarginBounds.Bottom - 100 Then
e.HasMorePages = HasMorePages
mRow = mRow - 1
Exit Sub
End If
Loop
mRow = 0
End With
End Sub ]
IN CREATING PREVIEWS MESSAGEBOX SHOWS THAT CREATES 2 PAGES. IN THE PRINDOCUMET AREA IN THE SCREEN SHOWS THE 1 PAGE. IN PRINT BUTTON PUT THE CODE :
[ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
CAN ANYONE HELP ME ?
THANKS
Comment