Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : imprimer listview [ Divers / General ] (naim1970)

lundi 14 juillet 2008 à 20:24:45 | imprimer listview

naim1970

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

 

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

lundi 14 juillet 2008 à 22:40:18 | Re : imprimer listview
lundi 14 juillet 2008 à 23:21:01 | Re : imprimer listview

naim1970

salut gillardg,

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

naim1970



Cette discussion est classé dans : columns, graphics, pd, if, defaultpagesettings


Répondre à ce message

Sujets en rapport avec ce message

pour masquer des colonnes en vba [ par tanerbus ] Je cherche un code pour masquer des colonnes automatiquement GDI+ CachedBitmap managé (Wrapper) [ par Kevin.Ory ] Bonsoir,Je cherche à développer un système de couches graphiques performant en .NET 2.0 dans le but de créer des animations graphiques fluides en plei Erreur de systax [ par DanMor498 ] Imports System.Data Imports system.Data.OleDb Imports</fo Ligne de commande pour relais [ par SpoonTD01 ] Bonjour, je travail sur un banc de test pour un appareil et j'aimerais tous faire contrôler par des relais. Donc ma question est qu Forcer écriture page suivante [ par CharlEm ] Bonjour,Le but de cette petite fonction me permet juste de récupérer tous les fichiers text d'un répertoire donné et d'en faire un seul gros fichier t Somme d'une ListBox [ par ElChauve ] Bonjour,Voilà, je voudrais pouvoir automatiser le calcul de la somme des valeurs d'une ListeBox, et afficher le résultat dans une ComboBox.J'ai dû pas Multiplication des solution dans une chaine [ par asketill ] Bonjour,Je cherche actuellement avec ce code source,Sub solveur_perso() Dim i As DoubleDim f As ObjectDim x As DoubleDim y As DoubleDim b As DoubleD Erreur d'exécution '3704' [ par jbprogram ] Salut Mon programme est bien compilé et l'exécution ok, développé sous vb6 comme client et sous access 2003 comme base de données. Au départ, ma bd Explication de code [ par lomatic ] Bonjour à tous,Il s'agit d'un fragment de code d'un programme permettant de déterminer la Classe d'une Adresse IP.J'ai du mal à interpreter ce que fai If dans Do While ... Loop [ par stanymi ] Bonjour,J'ai un pb assez intrigant je dois dire...Lorsque je tente de faire un contrôle avec un if dans ma boucle Do While... Loop,J'ai le message d'e


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,359 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.