Bonjour à tous les développeurs

Je me suis mi à la programmation il y a peu et j'ai créé une petite application ou je souhaites imprimer un panel avec un autoscrollbar.

Mon panel contient uniquement des "labels" et des "picturebox", certains label possèdent un backcolor

Avec un peu de recherche sur mon amis google , j'ai donc trouvé ce code qui fonctionne trés trés bien :

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
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
76
77
78
Static page As Integer = 1
 
        Dim startPosition As Integer = (page - 1) * PrintDocument1.DefaultPageSettings.Bounds.Height
 
        Static maxPages As Integer = 0
 
        If page = 1 Then
 
            For Each ctrl As Control In Me.Panel1.Controls
 
                If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Or TypeOf ctrl Is PictureBox Then
 
                    ctrl.Tag = Int((ctrl.Top + ctrl.Height) / PrintDocument1.DefaultPageSettings.Bounds.Height) + 1
 
                    If CInt(ctrl.Tag) > maxPages Then maxPages = CInt(ctrl.Tag)
 
                End If
 
            Next
 
        End If
 
        For Each ctrl As Control In Me.Panel1.Controls
 
            If val(ctrl.Tag) = page Then
 
                Dim sf As New System.Drawing.StringFormat
 
                If TypeOf ctrl Is TextBox Then
 
                    If DirectCast(ctrl, TextBox).TextAlign = HorizontalAlignment.Right Then
 
                        sf.Alignment = StringAlignment.Far
 
                    Else
 
                        sf.Alignment = StringAlignment.Near
 
                    End If
 
                ElseIf TypeOf ctrl Is Label Then
 
                    If DirectCast(ctrl, Label).TextAlign = ContentAlignment.TopLeft Then
 
                        sf.Alignment = StringAlignment.Near
 
                    ElseIf DirectCast(ctrl, Label).TextAlign = ContentAlignment.TopRight Then
 
                        sf.Alignment = StringAlignment.Far
 
                    End If
 
                End If
 
 
                sf.FormatFlags = StringFormatFlags.NoClip
 
                e.Graphics.DrawString(ctrl.Text, ctrl.Font, New SolidBrush(ctrl.ForeColor), New RectangleF(ctrl.Left, ctrl.Top - startPosition, ctrl.Width + 50, ctrl.Height), sf)
 
            End If
 
        Next
 
        page += 1
 
        If page > maxPages Then
 
            e.HasMorePages = False
 
            page = 1
 
            maxpages = 0
 
        Else
 
            e.HasMorePages = True
 
        End If
Je n'arrive pas à prendre en compte les picturebox et le "BackColor" des labels , pourriez-vous m'aiguiller sur ce que je devrai ajouter ??

Merci d'avance à tous ceux qui pourront m'aider