Results 1 to 4 of 4

Thread: Print Dialog

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    42

    Print Dialog

    I am trying to figure out how to bring up a crystal report in print preview without using a report viewer, or bringing up the report in advance. I found an example on the web that helped me figure out how to use the print dialog etc, but I haven't figured out how to adapt it so I could preview a crystal report instead of the drawling used in the example. Here is what I am working with...

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ' Make a PrintDocument and attach it to
    3.         ' the PrintPreview dialog.
    4.         dlgPrintPreview.Document = PreparePrintDocument()
    5.  
    6.         ' Preview.
    7.         dlgPrintPreview.WindowState = FormWindowState.Maximized
    8.         dlgPrintPreview.ShowDialog()
    9.     End Sub
    10.     Private Function PreparePrintDocument() As PrintDocument
    11.         ' Make the PrintDocument object.
    12.         Dim print_document As New PrintDocument
    13.  
    14.         ' Install the PrintPage event handler.
    15.         AddHandler print_document.PrintPage, AddressOf Print_PrintPage
    16.  
    17.         ' Return the object.
    18.         Return print_document
    19.     End Function
    20.  
    21.  
    22.     ' Print the next page.
    23.     Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
    24.         ' Draw a rectangle at the margins.
    25.         e.Graphics.DrawRectangle(Pens.Black, e.MarginBounds)
    26.  
    27.         ' Draw a thick, dashed ellipse.
    28.         Dim dotted_pen As New Pen(Color.Black, 5)
    29.         dotted_pen.DashStyle = Drawing2D.DashStyle.Dash
    30.         e.Graphics.DrawEllipse(dotted_pen, e.MarginBounds)
    31.         dotted_pen.Dispose()
    32.  
    33.         ' Draw a thick diamond.
    34.         Dim x0 As Integer = e.MarginBounds.X
    35.         Dim y0 As Integer = e.MarginBounds.Y
    36.         Dim wid As Integer = e.MarginBounds.Width
    37.         Dim hgt As Integer = e.MarginBounds.Height
    38.         Dim pts() As Point = { _
    39.             New Point(x0, y0 + hgt \ 2), _
    40.             New Point(x0 + wid \ 2, y0), _
    41.             New Point(x0 + wid, y0 + hgt \ 2), _
    42.             New Point(x0 + wid \ 2, y0 + hgt) _
    43.         }
    44.         e.Graphics.DrawPolygon(New Pen(Color.Black, 5), pts)
    45.  
    46.         ' There are no more pages.
    47.         e.HasMorePages = False
    48.     End Sub

    Any ideas on where I need to go from here, or am I on the wrong track all together? Thanks!

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Print Dialog

    I'm afraid you are barking up the wrong tree - to print a crystal report use the ReportDocument.PrintToPrinter Method

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    42

    Re: Print Dialog

    Thanks! I'll look into that.

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    42

    Re: Print Dialog

    Wow, it looks like this will make things a lot easier. The only problem is that I am having problems now getting it to show a print dialog. It seems like the method was just made to automatically print to a specific printer. If anybody knows how I can use the windows printer dialog with the above mentioned method let me know. In the mean time I will keep searching. Thanks again! Here is what I am using now...

    Dim crReportDocument As ReportDocument
    crReportDocument = New ReportDocument
    crReportDocument = New CrystalReport1
    crReportDocument.PrintOptions.PaperSource = CrystalDecisions.[Shared].PaperSource.Auto
    crReportDocument.PrintToPrinter(1, True, 1, 1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width