Bonjour,

Je fait actuellement une conversion d'un projet VB6 vers le VB.net 2010

Et je but sur l'impression de données.
J'ai deja cherche mais je tombe toujours sur l'impression d'un document texte ou photo.

En VB6 j'imprime les donnée que contient un Flexgrid. Dans ma conversion se sera un Datagirdview mais la n'est pas le problème.


Voici le code VB6
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
Private Sub cmdPrint_Click()
Dim leftTab As Integer
Dim indice As Integer
 
    Protocol.WaitEndSend  'Wait for end of transaction before opening cmdDialog
    MDIWin50.CommonDialog.CancelError = True
    MDIWin50.CommonDialog.Flags = cdlPDPrintSetup
    On Error GoTo ErrHandler
    MDIWin50.CommonDialog.DialogTitle = LoadPrgString(MSG_PRINT_HISTOFILE)
    MDIWin50.CommonDialog.ShowPrinter
    leftTab = 500
    If flxGridHistory.Rows <> 0 Then
      Printer.Print ("********************************************************")
      Printer.Print ("" & lblEditFrom.caption & "           " & txtEdited.caption & "           " & Now)
      Printer.Print ("********************************************************")
      Printer.Print ""
      Printer.Print ""
      Printer.Print (flxGridHistory.Rows - 1 & " alarms")
      Printer.Print ""
 
      Printer.Font.Bold = True
      For indice = 0 To flxGridHistory.Rows - 1
        If indice > 0 Then
          Printer.Font.Bold = False
        End If
 
        Printer.CurrentX = leftTab + 200
        Printer.Print flxGridHistory.TextMatrix(indice, 1);
        Printer.CurrentX = leftTab + 2000
        Printer.Print flxGridHistory.TextMatrix(indice, 2);
        Printer.CurrentX = leftTab + 3500
        Printer.Print flxGridHistory.TextMatrix(indice, 3);
        Printer.CurrentX = leftTab + 6000
        Printer.Print flxGridHistory.TextMatrix(indice, 5);
        Printer.Print ""
 
      Next
    End If
    Printer.EndDoc
    Exit Sub
 
ErrHandler:
    Exit Sub
 
End Sub
J'ai vu que l'objet PrintDialog peux donc remplacer le CommonDialog
Mais ensuite printer n'existe pas en .net.

J'ai vu aussi sur certain tuto que l'on utilise un événement mais j'ai du mal a comprendre tous cela et surtout pour l'adapter à mon cas puisque l'on crée le document ligne par ligne.

L’idéal pour que je puisse avoir une méthode portable serait que je face ma même chose mais en passant en paramètre une collection ou autre puis imprimer cette collection.

Je pensais a créer un document texte temporaire puis l'imprimer et le supprimer, mais cela me semble d'un autre temps. Quoi que ce soit peut être la solution.

Merci de votre aide