Imports System.Drawing.Printing
Public Class frmAffichageProfil
    Public WithEvents pdoc As New PrintDocument()
    Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
    Private Sub frmAffichageProfil_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Location = New Point(100, 10)
    End Sub

    Private Sub BtnImprimer_Click(sender As Object, e As EventArgs) Handles BtnImprimer.Click
        Dim Affichage_Impression As Integer = 1
        'Pour déclencher l'impression
        Try
            Select Case Affichage_Impression
                Case 1 'impression du dessin de ferraillage
                    pdoc.Print()
                    '  If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then pdoc.Print()
                    'affichage de la courbe d'interaction actif
                    '        frmInteraction.pdoc.Print()
                    '        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                    '            frmInteraction.pdoc.Print()
                    '        End If
                    '    Case 2 'affichage du ferraillage du poteau Actif
            End Select
        Catch ex As Exception
            MessageBox.Show("Erreur lors de l'impression:" & Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace, "Impression ...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        End Try
    End Sub

    Private Sub BtnAperçuAvantImpression_Click(sender As Object, e As EventArgs) Handles BtnAperçuAvantImpression.Click
        Dim Affichage_Impression As Integer = 1
        'Pour déclencher l'impression
        Try
            Select Case Affichage_Impression
                Case 1 'impression du dessin de ferraillage
                    AddHandler pdoc.PrintPage, AddressOf pdoc_PrintPage
                    Dim dllg As New PrintPreviewDialog
                    dllg.Document = pdoc
                    dllg.Document.DefaultPageSettings.Landscape = False
                    dllg.ShowDialog()
                    'affichage de la courbe d'interaction Actif
                    '        AddHandler FrmCourbe.pdoc.PrintPage, AddressOf FrmCourbe.pdoc_PrintPage
                    '        Dim dllg As New PrintPreviewDialog
                    '        dllg.Document = FrmCourbe.pdoc
                    '        dllg.Document.DefaultPageSettings.Landscape = True
                    '        dllg.ShowDialog()
                    '    Case 2 'affichage du ferraillage du poteau actif
            End Select
        Catch ex As Exception
            MessageBox.Show("Erreur lors de la visualisation avant impression:" & Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace, "Impression ...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        End Try
    End Sub
    Public Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage
        Dim g As Graphics = e.Graphics
        Dim hauteur, largeur As Integer 'oriX, oriY,

        g.PageUnit = GraphicsUnit.Millimeter
        With pdoc.DefaultPageSettings
            .Landscape = False ' impression en mode paysage

        End With
        hauteur = 297  'provisoire
        largeur = 210 'provisoire
        ' Call Affichage_Courbes(g, 3, largeur, hauteur, 2)
        Call Dessin_Litho_Pressio(g, 3, largeur, hauteur)
    End Sub
End Class