begin process at 2012 02 14 06:37:46
  Trouver un code source :
 
dans
 
Accueil > Forum > 

VB.NET et VB 2005

 > 

Divers

 > 

General

 > 

imprimer listview


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

imprimer listview

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ée 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 keydown et rowcolchange [ par abdo78 ] salut Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer) If DBGrid1.Col = 2 Or DBGrid1.Col = 0 Then DBGrid1.Col rempli base donnée [ par lamranilamrani ] salut j'ai un probleme dans mon programma vb lorsque j'ajoute un enregistrement dans ma base de donnée on utilisant le bouton AJOUTER il 'ajoute mai Datagrid et textbox [ par ressore ] Bonjour, je reviens vers vous pour une petite question, pour être clair dans mon form j'utilise un datagrid et dans une textbox je souhaite afficher Boucle dans un if? [ par Tokki ] Bonjour tous le monde, j'aimerais savoir si il y a la possibilité de mettre une boucle dans une condition if en VBA? Du genre : [code=vbs]if for j Urgent problème de variables dans mon programme [ par arween76 ] Bonsoir, Je débute en VB.Net. J'ai créé un programme de création de répertoire. Il fonctionne bien ... sauf que si je crée un répertoire puis que je Aide Macro Suppression Doublons [ par HiiiCoach ] Bonjour à tous, Je me tourne vers vous pour un besoin urgent et vous remercie d'avance de l'aide que vous m'apporterez. Il y a quelques semaines, j' Commendes de console fr [ par dayvid ] Bonjour ! Je débute juste et j'ai commencer ceci Q'uen penssez-vous ? [code=vb]Module Module_Console ''' ''' Permet de choisir le titre de [Catégorie modifiée VB6 -> VBA] Copier coller sur une ligne qui a été créée par un userform [ par zuip ] Bonjour à tous, voici mon soucis, je fais ajouter une ligne à une feuille excel par un userform. sur la colonne A apparaitra le nom de l'agence, et j' aide pour script sur droits sur répertoire [ par fire90 ] Bonjour j'ai créer un script qui crée des utilisateurs en utilisant un fichier excel. Il crée les uo et sous uo et place les utilisateurs dans les gro


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
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

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,638 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales