?
Solved

Printing in VB.NET 2008 question

Posted on 2009-12-30
3
Medium Priority
?
176 Views
Last Modified: 2012-05-08
I can't figure out how to include data in the preview dialog.  I will get it to show, but it doesn't contain any data.  What changes do I need to make?  
Thanks in advance.
Agent909

Public Class frmPrint
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'PrintDocument1.Print()  ' this works, but I want to preview it first
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim printFont As Font
        Dim txtH As Integer = 0
        Dim txtW As Integer = 0
        Dim LMargin As Integer = 0
        Dim TMargin As Integer = 0
        Dim lineToPrint As String

        With PrintDocument1.DefaultPageSettings
            txtH = .PaperSize.Height - .Margins.Top - .Margins.Bottom
            txtW = .PaperSize.Width - .Margins.Left - .Margins.Right
            LMargin = PrintDocument1.DefaultPageSettings.Margins.Left
            TMargin = PrintDocument1.DefaultPageSettings.Margins.Top
        End With

        lineToPrint = "Yahoo!"
        printFont = New Font("Courier New", 10)
        Dim SF As New System.Drawing.StringFormat
        SF.LineAlignment = StringAlignment.Near

        e.Graphics.DrawString(lineToPrint, printFont, Brushes.Black, LMargin, TMargin, SF)
        e.HasMorePages = False

        PrintPreviewDialog1.ShowDialog()  'the dialog shows, but does not show "Yahoo!"
    End Sub
End Class
0
Comment
Question by:Agent909
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 26149858
According to http://msdn.microsoft.com/en-us/library/274tyhz7.aspx

Do something like the following:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.PrintPreviewDialog1.Document = Me.PrintDocument1
        Me.PrintPreviewDialog1.ShowDialog()
    End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Agent909
ID: 31671424
Works great!  Thank you!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26150489
NP :)
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question