[2005] I need help with Print Preview?
Hi
I don't know why I can't preview the page, this code is from PrintDocument1:
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim horizontalprint As Single
Dim verticalprint As Single
horizontalprint = e.MarginBounds.Left
verticalprint = e.MarginBounds.Top
Dim printfont As New Font("arial", 12)
Dim lineheightsingle As Single = printfont.GetHeight
For listindexinteger As Integer = 0 To Me.StudentList.Items.Count - 1
e.Graphics.DrawString(Me.StudentList.Items(listindexinteger).ToString() & Me.DepartmentList.Items(listindexinteger).ToString() & Me.MarkList.Items(listindexinteger).ToString(), printfont, Brushes.Black, horizontalprint, verticalprint)
verticalprint += lineheightsingle
Next listindexinteger
End Sub
and this code is in Print preview button:
Code:
Private Sub printbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbtn.Click
PrintPreviewDialog1.ShowDialog()
End Sub
can you see the problem there I tried it before and it works I don't why it doesn't work now :rolleyes:
thanks
Re: [2005] I need help with Print Preview?
this will work
vb Code:
Private Sub printbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbtn.Click
' Create the document and attach an event handler.
Dim MyDoc As New PrintDocument()
AddHandler MyDoc.PrintPage, AddressOf MyDoc_PrintPage
Dim dlgPreview As New PrintPreviewDialog
dlgPreview.Document = MyDoc
dlgPreview.WindowState = FormWindowState.Maximized
dlgPreview.Show()
end sub
Private Sub MyDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim horizontalprint As Single = e.MarginBounds.Left
Dim verticalprint As Single = e.MarginBounds.Top
Dim printfont As New Font("arial", 12)
Dim lineheightsingle As Single = printfont.GetHeight
For listindexinteger As Integer = 0 To Me.StudentList.Items.Count - 1
e.Graphics.DrawString(Me.StudentList.Items(listindexinteger).ToString() & Me.DepartmentList.Items(listindexinteger).ToString() & Me.MarkList.Items(listindexinteger).ToString(), printfont, Brushes.Black, horizontalprint, verticalprint)
verticalprint += lineheightsingle
Next listindexinteger
end sub
Re: [2005] I need help with Print Preview?
Did you forget to set PirntPreviewDialog1.Document to PrintDocument1?
Re: [2005] I need help with Print Preview?
oh yes I forgot to do that :blush: hehehe .. well now all codes are working fine, thanks a lot :bigyello: