imprime un document que l'on créer avec les outil graphic de la class printpage d'un printdocument
l'image au nom de Graphique c'est l'image de ma première source comment faire un graphique
Source / Exemple :
Imports System.IO
Public Class F_Impression
Private cpt As Integer = 0
Public Sub FichierImprimer()
With PageSetupDialog
.Document = PrintDocument
.PageSettings.Margins.Bottom = 150
.PageSettings.Margins.Top = 150
.PageSettings.Margins.Left = 100
.PageSettings.Margins.Right = 100
If .ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
PrintDocument.DefaultPageSettings = .PageSettings
End With
With PrintDialog
.Document = PrintDocument
.AllowSelection = True
.AllowSomePages = True
If .ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
PrintDocument.PrinterSettings = .PrinterSettings
PrintDocument.DocumentName = "Document imprimer sur " & .PrinterSettings.PrinterName
PrintDocument.Print()
End With
End Sub
Private Sub PrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage
Dim Police As New Font("Arial", 12)
Dim Ft As New Font("Arial", 10)
Dim g As Graphics = e.Graphics
Dim hdiv As Single = (375 / 11)
Dim hori As Single = ((e.MarginBounds.Top + 170) + 375) - hdiv
Dim vdiv As Single = (e.MarginBounds.Width / 5)
Dim verti As Single = e.MarginBounds.Width - vdiv
Dim TabeString(2, 11) As String
Dim i As Integer = 0
Dim TableEnTete() As String = {"colonne 1", "colonne 2", "colonne 3", "colonne 4", "colonne 5"}
g.DrawString("code", Police, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top)
g.DrawString("Nom Prénom", Police, Brushes.Black, e.MarginBounds.Left + 200, e.MarginBounds.Top)
g.DrawString("Date de naissance", Police, Brushes.Black, e.MarginBounds.Left + 400, e.MarginBounds.Top)
g.DrawString("Age", Police, Brushes.Black, e.MarginBounds.Left + 600, e.MarginBounds.Top)
If cpt = 0 Then
g.DrawString("Text", Ft, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top + 30)
TabeString(0) = "0"
TabeString(1) = "1"
TabeString(2) = "2"
TabeString(3) = "3"
TabeString(4) = "4"
TabeString(5) = "5"
TabeString(6) = "6"
TabeString(7) = "7"
TabeString(8) = "8"
TabeString(9) = "9"
TabeString(10) = "10"
g.DrawRectangle(Pens.Black, New Rectangle(47, e.MarginBounds.Top + 170, 198, 375))
g.DrawLine(Pens.Black, CInt((245 + 50) / 2), e.MarginBounds.Top + 170, CInt((245 + 50) / 2), ((e.MarginBounds.Top + 170) + 375))
While i <= 10
If i <> 10 Then g.DrawLine(Pens.Black, 47, hori, 245, hori)
g.DrawString(TabeString(0, i), Me.Font, Brushes.Black, 50, hori + 10)
g.DrawString(TabeString(1, i), Me.Font, Brushes.Black, CInt((245 + 50) / 2) + 3, hori + 10)
hori -= hdiv
i += 1
End While
g.DrawImage(Graphique, 250, (e.MarginBounds.Top + 170))
g.DrawString("text", Ft, Brushes.Black, e.MarginBounds.Left, ((e.MarginBounds.Top + 190) + 375))
cpt = 1
Else
g.DrawRectangle(Pens.Black, New Rectangle(e.MarginBounds.Left, e.MarginBounds.Top + 30, (e.MarginBounds.Width - 1) - 30, (e.MarginBounds.Height - 1) - 30))
For a As Integer = 4 To 0 Step -1
g.DrawString(TableEnTete(a), Ft, Brushes.Black, verti + 60, e.MarginBounds.Top + 35)
If a <> 0 Then g.DrawLine(Pens.Black, verti, e.MarginBounds.Top + 30, verti, e.MarginBounds.Height + 38)
verti -= vdiv
Next
g.DrawLine(Pens.Black, e.MarginBounds.Left, e.MarginBounds.Top + 55, e.MarginBounds.Width + 28, e.MarginBounds.Top + 55)
cpt = 0
End If
If cpt = 1 Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dllg As New PrintPreviewDialog
With PageSetupDialog
.Document = PrintDocument
.PageSettings.Margins.Bottom = 150
.PageSettings.Margins.Top = 150
.PageSettings.Margins.Left = 100
.PageSettings.Margins.Right = 100
If .ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
PrintDocument.DefaultPageSettings = .PageSettings
End With
dllg.Document = PrintDocument
dllg.ShowDialog()
Me.Close()
End Sub
End Class
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.