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
| Private Sub BtnImprimer_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BtnImprimer.Click
Dim MiseEnPage As New PageSetupDialog
Dim MonDoc As New Printing.PrintDocument
With MiseEnPage
.Document = MonDoc
.AllowOrientation = False
.AllowPaper = False
.EnableMetric = True
.MinMargins = New Printing.Margins(100, 100, 50, 50)
.ShowDialog(Me)
.Dispose()
End With
' Tu attaches l'évenement PrintPage à ca méthode d'impression
AddHandler MonDoc.PrintPage , addressOf MonDoc_PrintPage
' Tu appels la fonction Print qui va appeler PrintPage
MonDoc.Print()
End Sub
' C'est dans cette méthode qu'on imprime réellement.
Private Sub MonDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim Police As New Font("Arial", 11)
Dim PoliceGras As New Font("Arial", 12, FontStyle.Bold)
Dim XPos, YPos As Single
Dim ChaineImpr As String
Using MyGraphics As Graphics = e.Graphics
Dim Picture As New Bitmap(Me.PictureBox1.Image)
MyGraphics.DrawImage(Picture, 2.0F * e.MarginBounds.Width / 3.0F, YPos)
Dim SautLigne As Single = MyGraphics.MeasureString("X", PoliceGras).Height
ChaineImpr = Me.TXTCIN.Text + " -- " + Me.TXTCNRPS.Text + " -- " + Me.TXTMutuel.Text
MyGraphics.DrawString(ChaineImpr, PoliceGras, Brushes.Black, XPos, YPos)
YPos = YPos + SautLigne * 1.5F
ChaineImpr = "Prenom : " + Me.TXTPreNomPers.Text
MyGraphics.DrawString(ChaineImpr, Police, Brushes.Black, XPos, YPos)
YPos = YPos + SautLigne * 1.5F
ChaineImpr = "Date de Recruttement : " + Me.TXTDateRecrutement.Text
MyGraphics.DrawString(ChaineImpr, Police, Brushes.Black, XPos, YPos)
YPos = YPos + SautLigne * 3.0F
End Using
End Sub |
Partager