Imprimer plusieurs pages en vb.net avec la fonction HasMorePages

phanoudev Messages postés 33 Date d'inscription mercredi 15 mars 2006 Statut Membre Dernière intervention 6 juillet 2006 - 17 mars 2006 à 13:14
phanoudev Messages postés 33 Date d'inscription mercredi 15 mars 2006 Statut Membre Dernière intervention 6 juillet 2006 - 17 mars 2006 à 17:14
Bonjour,
je veux imprimer une msFlexGrid donc j'ai creer un bouton et un fonction qui imprime mais lorsque le debugger arrive sur la fonction HasMorePages, il ouvre une boite de dialogue indiquant impression mais rien ne se passe et le prog se bloque. Si je veux imprimer une seule page il n'ya pas de pb. voici le code des 2 fonctions, si quelqu'un a une idee merci d'avance pour l'aide



Private
Sub cmdPrint_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles cmdPrint.Click


printFont =
New Font("Arial", 10)


printDoc =
New PrintDocument



AddHandler printDoc.PrintPage,
AddressOf
Me.printDoc_PrintPage


printDoc.Print()



End
Sub



Dim printDoc
As PrintDocument



Dim lpp
As
Single = 0
'number of lines per page



Dim yPos
As
Single = 0



Dim count
As
Integer = 1
'number of the line



Dim line
As
String



Dim p
As
Short = 0



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



'Dim lpp As Single = 0 'number of lines per page



'Dim yPos As Single = 0



'Dim count As Integer = 1 'number of the line



Dim leftMargin
As
Single = e.MarginBounds.Left



Dim topMargin
As
Single = e.MarginBounds.Top



'Dim line, strTableData As String



'Dim intCnt, intDataCnt, i, intIndex, p As Short



On
Error
GoTo ErrorHandler



'p = 0



'calcul the number of line per page



'Height of the page/height of the font


lpp = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)


yPos = topMargin - 100


e.Graphics.DrawString("Valve Test Data for " & cboValveType.Text & " " & cboSpoolType.Text,
New Font("Arial", 14, FontStyle.Underline), Brushes.Black, leftMargin, yPos,
New StringFormat)


yPos = topMargin - 30


e.Graphics.DrawString("IDENTIFICATION", printFont, Brushes.Black, 0.5 * leftMargin, yPos,
New StringFormat)


e.Graphics.DrawString("DESCRIPTION", printFont, Brushes.Black, 2.5 * leftMargin, yPos,
New StringFormat)


e.Graphics.DrawString("VALUE", printFont, Brushes.Black, 6 * leftMargin, yPos,
New StringFormat)


yPos = topMargin



'read one line of the dataGrid, the 1st line of the page


line = msFlexGridConfig.get_TextMatrix(p + 1, 1)



'loop writing each line



While (count < lpp
And line <>
Nothing
And (count + p < msFlexGridConfig.Rows()))


yPos = yPos + printFont.GetHeight(e.Graphics)



'write the 1 column


e.Graphics.DrawString(line, printFont, Brushes.Black, 0.5 * leftMargin, yPos,
New StringFormat)



'write the 2 column


line = msFlexGridConfig.get_TextMatrix(count + p, 2)


e.Graphics.DrawString(line, printFont, Brushes.Black, 2.5 * leftMargin, yPos,
New StringFormat)



'write the 3 column


line = msFlexGridConfig.get_TextMatrix(count + p, 3)


e.Graphics.DrawString(line, printFont, Brushes.Black, 6 * leftMargin, yPos,
New StringFormat)


count = count + 1



If (count + p < msFlexGridConfig.Rows())
Then
'((count < lpp) And (count < msFlexGridConfig.Rows())) Then


line = msFlexGridConfig.get_TextMatrix(count + p, 1)



Else


line =
Nothing



End
If



End
While



'if there are still lines in the dataGrid



If (line <>
Nothing)
Then


p = count


count = 0


yPos = topMargin


e.HasMorePages =
True 'partie a pb



Else


e.HasMorePages =
False



Exit
Sub



End
If


ErrorHandler:


MsgBox("Error printing data to printer.", MsgBoxStyle.ApplicationModal + MsgBoxStyle.Critical, MMain.APP_NAME)



Exit
Sub



End
Sub

1 réponse

phanoudev Messages postés 33 Date d'inscription mercredi 15 mars 2006 Statut Membre Dernière intervention 6 juillet 2006 1
17 mars 2006 à 17:14
en fait le probleme ne vient pas de hasmorepages mais du erreur handler, je ne sais pas l'expliquer, si je le met en commentaire le prog fonctionne et si je le remet il envoi un message d'erreur mais imprime quand meme????
Si quelqu'un sait m'expliquer ce qu'il se pqsse, je le remercie
0
Rejoignez-nous