Printpreview
I have a file c:/Temp.txt i want a print preview in vb.net... On button click...can anyone tell me
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Dec 13, 2009, 2:16 AM
Private printerSettings As System.Drawing.Printing.PageSettingsPrivate printingFont As Font
Private streamReader As StreamReader
Private filename As String
Private Sub mnuPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPreview.Click
If Not filename Is Nothing Then
Try
streamReader = New StreamReader(filename)
Try
printingFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
If Not (printerSettings Is Nothing) Then
pd.DefaultPageSettings = printerSettings
End If
With PrintPreviewDialog1
.Document = pd
.ShowDialog()
End With
Finally
streamReader.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message, "Print", _
MessageBoxButtons.OK, MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1)
End Try
Else
MessageBox.Show("Please select file first.", "Print", _
MessageBoxButtons.OK, MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1)
End If
End Sub