Imprimer listview

Signaler
Messages postés
26
Date d'inscription
mardi 15 juin 2004
Statut
Membre
Dernière intervention
29 octobre 2008
-
Messages postés
26
Date d'inscription
mardi 15 juin 2004
Statut
Membre
Dernière intervention
29 octobre 2008
-
Bonjour,

Le projet de Labout, trier, couleur et impression est remarquable.
Ce dernier j’ai intégré dans un projet Listview mais j’ai un petit blém.

- La première colonne de la listview ne s’affiche pas dans l’aperçu de l’impression !!!
- Et si les totalités des colonnes, est plus grande que la page paysage, le reste des colonnes ne s’affichent pas sur une page supplémentaire!

Merci de votre aide.

naim <?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" /??>






 






Voici le code




Public Sub PrintListview()



        Dim ppdlg As New PrintPreviewDialog



        Dim idepart As Integer



        Dim iMoins As Integer



        Dim w As Integer = 2



        Dim oldAtabvertical() As Integer



        Y = 0



        iCol = 0



        pagenum = 0



        LargeurMaxi = 0



 





        If _mcolonne0Vide = True Then



            idepart = 1



        Else



            idepart = 0



        End If



        ReDim oldAtabvertical(Me.Columns.Count - 1)



        ReDim atabVertical(Me.Columns.Count - 1)



        ' je stocke les valeurs d'origine



        For i = idepart To Me.Columns.Count - 1



            oldAtabvertical(i) = Me.Columns(i).Width



        Next



        Me.AjusterLargeurDesColonnes(Me, Me.emode.TitreouContenu)



 





 





        For i = 0 To Me.Columns.Count - 1



            w = w + Me.Columns(i).Width + 4



        Next



        Me.parentForm = Me.FindForm()



        If Not Me.parentForm Is Nothing Then



            Me.parentForm.Width = w



        End If



 





 





        AddHandler m_pd.PrintPage, AddressOf PrintDocument1_PrintPage



        With ppdlg



            ' m_pd.Print() si l'in ne souhaite pas l'aperçu



 





            .PrintPreviewControl.Document = m_pd



            ' calcul de la largeur de la liste



            'If Me.bDejaTrie Then



            '    iMoins = 16



            'End If



            For i = idepart To Me.Columns.Count - 1



                LargeurMaxi = LargeurMaxi + Me.Columns(i).Width() - iMoins



            Next



 





            If LargeurMaxi > m_pd.DefaultPageSettings.PaperSize.Width - (m_pd.DefaultPageSettings.Margins.Left + m_pd.DefaultPageSettings.Margins.Right) + 10 Then



                m_pd.DefaultPageSettings.Landscape = True



            Else



                m_pd.DefaultPageSettings.Landscape = False



            End If



            .WindowState = FormWindowState.Maximized



 





            start = 0



            .ShowDialog()



            .Dispose()



        End With



        RemoveHandler m_pd.PrintPage, AddressOf PrintDocument1_PrintPage



        Dim isz As SizeF



        Dim g As Graphics = Me.CreateGraphics()



        ' je restitue els valeur d'origine



        For i = idepart To Me.Columns.Count - 1



            Me.Columns(i).Width = oldAtabvertical(i)



        Next



        iCol = 0



        start = 0



 





    End Sub



 





    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)



        'Public Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage



        Dim tabf As Font = _mfontText ' New Font("Arial", 8)



        Dim titf As Font = _mfontEntete ' New Font("Arial", 12, FontStyle.Regular)



        Dim fbaspage As Font = _mfontBaspage



        Dim titfg As Font = Me.Font  '_ mfontEntete 'New Font("Arial", 12, FontStyle.Bold)



        Dim tit As Font = _mfontTitre ' New Font("Arial", 12, FontStyle.Bold)



        Dim iPostitre As Integer



        Dim isz As SizeF



        Dim pen As New Pen(_mcolorcadre, 1)



        Dim myBrushText As New SolidBrush(_mcolortext)



        Dim myBrushTextNegatif As New SolidBrush(_mColorNegatif)



        Dim myBrushCadre As New SolidBrush(_mcolorcadre)



        Dim myBrushTitre As New SolidBrush(_mcolortitre)



        Dim myBrushBasPage As New SolidBrush(_mcolorBasPage)



        Dim iTop As Integer



        Dim ipostext As Integer



        Dim HauteurPage As Integer



        Dim LargeurPage As Integer



        Dim idepart As Integer



        Dim hligne As Single



        Dim nbLigneparpage As Integer



        If Me.Colonne0Vide = True Then



            idepart = 1



        Else



            idepart = 0



        End If



        titfg = New Font(Me.Font.Name, Me.Font.Size, FontStyle.Bold)



        If m_pd.DefaultPageSettings.Landscape = True Then



  
         LargeurPage = m_pd.DefaultPageSettings.PaperSize.Height



            HauteurPage = m_pd.DefaultPageSettings.PaperSize.Width + 125



        Else



            LargeurPage = m_pd.DefaultPageSettings.PaperSize.Width



            HauteurPage = m_pd.DefaultPageSettings.PaperSize.Height



        End If



        isz = e.Graphics.MeasureString("bonjour", tabf)



        hligne = isz.Height



 





 





        isz = e.Graphics.MeasureString(_mTitre, tit)



        iPostitre = CInt((LargeurMaxi - CInt(isz.Width)) / 2) + m_pd.DefaultPageSettings.Margins.Left



        tx = m_pd.DefaultPageSettings.Margins.Left - 70



        Y = m_pd.DefaultPageSettings.Margins.Top - 20



        e.Graphics.DrawString("Edité le : " & Now, tabf, myBrushText, 80, 25)



 





        e.Graphics.DrawString(_mTitre, tit, myBrushTitre, iPostitre, Y - 20)



        isz = e.Graphics.MeasureString(_mTitre, tit)



        Y = Y + CInt(isz.Height) - 20



        Dim hDispo As Integer



        hDispo = HauteurPage - Y - 40



        nbLigneparpage = CInt(hDispo / (hligne + 4))



        If hDispo / (hligne + 4) <> CInt(hDispo / (hligne + 4)) Then



            nbLigneparpage = nbLigneparpage - 1



        End If



 





        If (Me.Items.Count / nbLigneparpage) - CInt(Me.Items.Count / nbLigneparpage) <= 0 Then



            nbpage = CInt(Me.Items.Count / nbLigneparpage)



        Else



            nbpage = CInt(Me.Items.Count / nbLigneparpage) + 1



        End If



        ' nbpage = HauteurPage / CInt(hligne) + 4



        For i = idepart To Me.Columns.Count - 1



            If Me.Columns(i).TextAlign = HorizontalAlignment.Left Then



                e.Graphics.DrawString(Me.Columns(i).Text, titfg, myBrushText, tx, Y)



            ElseIf Me.Columns(i).TextAlign = HorizontalAlignment.Right - 20 Then



                isz = e.Graphics.MeasureString(Me.Columns(i).Text, titfg)



                ipostext = tx + Me.Columns(i).Width - CInt(isz.Width)



                e.Graphics.DrawString(Me.Columns(i).Text, titfg, myBrushText, ipostext - 40, Y)



            Else  ' center



                isz = e.Graphics.MeasureString(Me.Columns(i).Text, titfg)



                ipostext = CInt(tx + (Me.Columns(i).Width - CInt(isz.Width)) / 2)



                e.Graphics.DrawString(Me.Columns(i).Text, titfg, myBrushText, ipostext - 3, Y)



            End If



            tx += Me.Columns(i).Width ' 110



        Next



        ' première horizontale



        iTop = Y - 10



        e.Graphics.DrawLine(pen, m_pd.DefaultPageSettings.Margins.Left - 70, Y - 10, tx - 2, Y - 10)



   
    ' deuxième horizontale



        e.Graphics.DrawLine(pen, m_pd.DefaultPageSettings.Margins.Left - 70, Y + 20, tx - 2, Y + 20)



        Y = Y + 20



        nbLigneparpage = CInt((HauteurPage - Y) / (CInt(hligne) + 4))



        atabVertical(0) = m_pd.DefaultPageSettings.Margins.Left - 2



        For itm = start To Me.Items.Count - 1



            tx = m_pd.DefaultPageSettings.Margins.Left - 70



            For i = idepart To Me.Columns.Count - 1



                Dim p1 As String



                Dim q1 As Decimal



 
              p1 = Me.Items(itm).SubItems(i).Text



                If f(i, 2) = "d" Then



                    q1 = tx + CInt((11 - Len(p1)) * 5.25)



                Else



                    q1 = tx



                End If



                If Me.Columns(i).TextAlign = HorizontalAlignment.Left Then



                    ' trop lent



                    'If Not IsDate(p1) Or Not IsNumeric(p1) Then



                    e.Graphics.DrawString(p1, tabf, myBrushText, q1, Y)



                    'Else



                    '    If CDbl(p1) < 0 Then



                    '        e.Graphics.DrawString(p1, tabf, myBrushTextNegatif, q1, Y)



                    '    Else



                    '        e.Graphics.DrawString(p1, tabf, myBrushText, q1, Y)



          
         '    End If



                    'End If



                ElseIf Me.Columns(i).TextAlign = HorizontalAlignment.Right Then



                    isz = e.Graphics.MeasureString(p1, tabf)



                    ipostext = tx + Me.Columns(i).Width - CInt(isz.Width)



                    If CDbl(p1) < 0 Then



                        e.Graphics.DrawString(p1, tabf, myBrushTextNegatif, ipostext - 5, Y)



                    Else



                        e.Graphics.DrawString(p1, tabf, myBrushText, ipostext - 5, Y)



  
                 End If



                Else  ' center



                    isz = e.Graphics.MeasureString(p1, tabf)



                    ipostext = CInt(tx + (Me.Columns(i).Width - CInt(isz.Width)) / 2)



                    ' trop lent



                    'If Not IsDate(p1) Or Not IsNumeric(p1) Then



                    e.Graphics.DrawString(p1, tabf, myBrushText, ipostext, Y)



                    'Else



                    '    If CDbl(p1) < 0 Then



                    '        e.Graphics.DrawString(p1, tabf, myBrushTextNegatif, ipostext, Y)



                    '    Else



                    '        e.Graphics.DrawString(p1, tabf, myBrushText, ipostext, Y)



                    '    End If



                    'End If



                End If



                tx += Me.Columns(i).Width '110



                If pagenum = 0 Then



                    atabVertical(i) = tx - 2



                End If



            Next



            Y = Y + CInt(hligne) + 4



            With m_pd.DefaultPageSettings



        
       If Y > HauteurPage - (m_pd.DefaultPageSettings.Margins.Bottom + m_pd.DefaultPageSettings.Margins.Top) + 20 Then



                    pagenum += 1



                    Y = HauteurPage - (m_pd.DefaultPageSettings.Margins.Bottom + m_pd.DefaultPageSettings.Margins.Top) + 20



                    ' horizontale



                    e.Graphics.DrawLine(pen, m_pd.DefaultPageSettings.Margins.Left - 70, Y + 14, tx - 2, Y + 14)



                    ' verticales



                    e.Graphics.DrawLine(pen, m_pd.DefaultPageSettings.Margins.Left - 70, iTop, m_pd.DefaultPageSettings.Margins.Left - 70, Y + 13)



                    For iCol = idepart To UBound(atabVertical)



                        e.Graphics.DrawLine(pen, atabVertical(iCol), iTop, atabVertical(iCol), Y + 14)



                    Next



 





                    Y = HauteurPage



                    ' ligne du bas



                    e.Graphics.DrawLine(pen, 0, Y - 50, LargeurPage + 50, Y - 50)



                    e.Graphics.DrawString(_mBasPage, fbaspage, myBrushBasPage, m_pd.DefaultPageSettings.Margins.Left - 20, Y - 40)



                    e.Graphics.DrawString("page: " & CType(pagenum, String) & " / " & nbpage, titf, myBrushText, LargeurPage - 120, Y - 155)



                    e.HasMorePages = True



                 
  start = itm + 1



                    If start > Me.Items.Count - 1 Then



                        Exit For



                    End If



                    iCol = 0



                    Exit Sub



                End If



            End With



        Next



        pagenum += 1



        If Y < HauteurPage Then



            ' horizontale



            e.Graphics.DrawLine(pen, m_pd.DefaultPageSettings.Margins.Left - 70, Y, tx - 2, Y)



            ' verticale



            e.Graphics.DrawLine(pen, m_pd.DefaultPageSettings.Margins.Left - 70, iTop, m_pd.DefaultPageSettings.Margins.Left - 70, Y)



            For iCol = idepart To UBound(atabVertical)



                e.Graphics.DrawLine(pen, atabVertical(iCol), iTop, atabVertical(iCol), Y)



            Next



 





            Y = HauteurPage 'Y + 20



            ' ligne du bas



            e.Graphics.DrawLine(pen, 0, Y - 50, LargeurPage + 50, Y - 50)



            'e.Graphics.DrawString("page: " & CType(pagenum, String), titf, myBrushText, LargeurPage - 120, Y - 155)



            e.Graphics.DrawString(_mBasPage, titf, myBrushBasPage, m_pd.DefaultPageSettings.Margins.Left - 20, Y - 40)



            e.Graphics.DrawString("page: " & CType(pagenum, String) & " / " & nbpage, titf, myBrushText, LargeurPage - 120, Y - 155)



        End If



        e.HasMorePages = False



 





    End Sub





naim1970

2 réponses

Messages postés
3275
Date d'inscription
jeudi 3 avril 2008
Statut
Membre
Dernière intervention
14 septembre 2014
4
éssaie avec ça j'ai déjà imprimé pas mal de trucs avec
http://www.vbfrance.com/codes/IMPRIMER-DATAGRIDVIEW-AUTRES-CONTROLES_46951.aspx
Messages postés
26
Date d'inscription
mardi 15 juin 2004
Statut
Membre
Dernière intervention
29 octobre 2008

salut gillardg,

Merci pour le lien,
Mais ton projet en question, a été créé avec vb 2005 le mien est en 2003.

naim1970