1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| ''' <summary>
''' Capture de la zone d'impression
''' </summary>
''' <remarks></remarks>
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphics()
'On imprimera la tab_control, on récupère donc la taille de l'un d'entre eux, sahcant qu'ils ont tous la même taille
Dim s As Size = Me.tc_etape0.Size
'On définit une image de la taille du tab_control
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
Dim point As Point
'On récupère le pojnt supérieur gauche du tab_control
point = tc_etape0.PointToScreen(New Point(0, 0))
'On capture l'écran à partir de ce point, avec les dimensions du tabcontrol
memoryGraphics.CopyFromScreen(point.X, point.Y, 0, 0, s)
End Sub
''' <summary>
''' Redimensionnement de l'image et impression
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'On récupère l'image à imprimer
Using MyGr As Graphics = e.Graphics
'On calcule le ratio pour la largeur de l'image
Dim LargImage As Double = memoryImage.Width / memoryImage.HorizontalResolution * 100
Dim RapX As Double = e.MarginBounds.Width / LargImage
'On calcule le ratio pour la hauteur de l'image
Dim HautImage As Double = memoryImage.Height / memoryImage.VerticalResolution * 100
Dim RapY As Double = e.MarginBounds.Height / HautImage
'On garde le ratio le plus petit pour redimensionner l'image afin que l'image imprimée ne sois pas coupée
RapX = IIf(RapX < RapY, RapX, RapY)
Dim RectSortie As New Rectangle(0, 0, Double.Parse(LargImage * RapX), CInt(HautImage * RapX))
'On définit l'emplacement d'impression de l'image sur la page
RectSortie.X = e.MarginBounds.X + Double.Parse((e.MarginBounds.Width - RectSortie.Width) / 2)
RectSortie.Y = e.MarginBounds.Y + Double.Parse((e.MarginBounds.Height - RectSortie.Height) / 2)
'Et on dessine l'image finale qui sera imprimée
MyGr.DrawImage(memoryImage, RectSortie)
End Using
End Sub
''' <summary>
''' Réglages de l'imprimante et lancement de l'impression
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimerToolStripMenuItem.Click
'Capture de la zone d'impression
CaptureScreen()
'Paramétrage
PrintDocument1.DocumentName = "Valorisation des stocks" & cb_mois.SelectedItem & " " & cb_annee.SelectedItem
Dim result As DialogResult = PrintDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
Dim PageSetupDialog As New PageSetupDialog()
PrintDocument1.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
PrintDocument1.PrinterSettings.Copies = PrintDialog1.PrinterSettings.Copies
PageSetupDialog.Document = PrintDocument1
PageSetupDialog.PageSettings.Landscape = True
'Impression
PrintDocument1.Print()
End If
End Sub |