not have the Print Dialog pop up when I use printreport to send to printer

I'm using Visual basic 2008 and  I would like to know if there's a way to not have the Print Dialog pop up when I use printreport to send to printer.
Private Sub frmRapport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Me.CrystalReport31.SetParameterValue(0, My.Settings.NoContrat.ToString)
        If not PrintDocument1.PrinterSettings.IsValid = False Then
            Me.CrystalReportViewer1.PrintReport()
            Me.Close()
        End If
    End Sub

Open in new window

sylvainhotteAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
You really didn't believe me.

Proof:


CrystalReportViewer
 
Public Overridable Sub PrintReport()
    Me.pageView.PrintReport
End Sub
 
PageView
 
Public Overridable Sub PrintReport()
    Dim activeDocument As ReportDocumentBase = Me.GetActiveDocument
    If (Not activeDocument Is Nothing) Then
        activeDocument.Print
    End If
End Sub
 
ReportDocumentBase
 
<DummyPermission(SecurityAction.Demand)> _
Public Sub Print()
    Dim settings As PrinterSettings
    Dim dialog As New PrintDialog { _
        .AllowSomePages = True _
    }
    settings = New PrinterSettings { _
        .MinimumPage = 1, _
        .FromPage = 1, _
        .MaximumPage = Me.GetLastPageNumber, _
        .ToPage = settings.MaximumPage _
    }
    If (settings.MinimumPage <= settings.MaximumPage) Then
        Dim exception As Exception
        Dim document As New PrintDocument { _
            .PrinterSettings = settings, _
            .DefaultPageSettings = { Landscape:=Me.isPaperLandscape } _
        }
        Dim kind As PaperKind = Me.getPaperKind
        Dim size As PaperSize
        For Each size In settings.PaperSizes
            If (size.Kind = kind) Then
                document.DefaultPageSettings.PaperSize = size
                Exit For
            End If
        Next
        dialog.Document = document
        Dim oK As DialogResult = DialogResult.OK
        New PrintingPermission(PrintingPermissionLevel.AllPrinting).Assert
        Try 
            oK = dialog.ShowDialog
        Catch exception1 As Exception
            exception = exception1
            ExceptionEventService.HandleExceptionEvent(Me, exception)
        Catch obj1 As Object
            exception = New Exception("Non-CLS Exception")
            ExceptionEventService.HandleExceptionEvent(Me, exception)
        End Try
        If (oK <> DialogResult.OK) Then
            settings = Nothing
        Else
            AddHandler dialog.Document.PrintPage, New PrintPageEventHandler(AddressOf Me.PrintPageEventHander)
            Me.CurHorizontalPage = 1
            If (settings.PrintRange = PrintRange.AllPages) Then
                Me.FromPage = 1
                Me.CurPage = 1
                Me.ToPage = settings.MaximumPage
                Me.TotalHorizontalPage = 1
            Else
                Me.FromPage = settings.FromPage
                Me.CurPage = Me.FromPage
                Me.ToPage = settings.ToPage
            End If
            Me.PrintCopies = settings.Copies
            Try 
                document.Print
            Catch exception2 As Exception
                exception = exception2
                ExceptionEventService.HandleExceptionEvent(Me, exception)
            Catch obj2 As Object
                exception = New Exception("Non-CLS Exception")
                ExceptionEventService.HandleExceptionEvent(Me, exception)
            End Try
        End If
    End If
End Sub
 
 
 

Open in new window

0
 
sylvainhotteAuthor Commented:
Hi!

Actually I did beleived you! The second question was psoted before your answer! I tried your suggestion and it work.

Thanks sorry if  I did not sound like  I beleived you

Sylvain
0
 
Bob LearnedCommented:
Aah, yes, the old two questions asked because the first one wasn't answered trick (d'oh).  That is why it it really confusing when this happens.
0
All Courses

From novice to tech pro — start learning today.