Printpreview
I have a file c:/Temp.txt i want a print preview in vb.net... On button click...can anyone tell me
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 12, 2009, 9:16 PM EST
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