Bonsoir à tous ce qui sont encore veille et bonne rêve à tous ce qui sont au lit.

J'ai une forme qui contienne des TextBox (Infos sur un individu) et une photo. Je veux imprimer cette fiche personnel, j'ai suivi un exemple d'un cours publier su développez.com

voici le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub BtnImprimer_Click(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles BtnImprimer.Click
 
 
        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
        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
 
        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

ça n'a pas marché. Il y a un message d'erreur qui apparait:

( System.InvalidCastException

Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.Drawing.Printing.PrintPageEventArgs'.
)

Je n'est rien compris à ce message, c'est pour cela que je cherche de l'aide.

Merci à tous.