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
| Private Sub BtnImprimer_Click(sender As Object, e As EventArgs) 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(0, 0, 0, 0)
'.ShowDialog(Me)
.Dispose()
End With
AddHandler MonDoc.PrintPage, AddressOf MonDoc_PrintPage
MonDoc.Print() ' Tu appels la fonction Print qui va appeler PrintPage
End Sub
Private Sub MonDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
' C'est dans cette méthode qu'on imprime réellement.
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
'----------------------- Impression de l'image -------------------------------
'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
MyGraphics.DrawString(ChaineImpr, PoliceGras, Brushes.Black, XPos , YPos)
YPos = YPos + SautLigne * 1.5F
ChaineImpr = Me.TXTPreNomPers.Text + "الإسم و اللقب : "
MyGraphics.DrawString(ChaineImpr, Police, Brushes.Black, XPos , YPos)
YPos = YPos + SautLigne * 1.5F
End Using
End Sub |
Partager