Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports System
Imports System.Drawing
Imports System.IO
Public Class Form1 'let op je eigen form naam
#Region " Print"
Private Sub BTPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTPrint.Click
Dim ppd As New PrintPreviewDialog
Dim PHi As Double
Dim PSize As Integer
With MyPrintDocument.PrinterSettings
Dim Ps As PaperSize
PHi = PSize * 20 + 350
Ps = New PaperSize("Cust", 800, PHi)
End With
headfont = New Font("Courier New", 16, FontStyle.Bold)
tableFont = New Font("Courier New", 10, FontStyle.Bold)
titlefont = New Font("Courier New", 12, FontStyle.Bold)
X1 = MyPrintDocument.DefaultPageSettings.Margins.Left
Dim pageWidth As Integer
With MyPrintDocument.DefaultPageSettings
pageWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
MyPrintDocument.DefaultPageSettings.Landscape = False
End With
MyPrintDocument.DefaultPageSettings.Margins = New Margins(20, 20, 200, 20)
X1 = 150
X2 = X1 '+ 10
X3 = X2 + pageWidth * 0.5
W1 = X2 - X1
W2 = X3 - X2
W3 = pageWidth - X3
ppd.Document = MyPrintDocument
ppd.ShowDialog()
End Sub
'FontStylemaak hier de fontstyle die je nodig hebt
Dim X1, X2, X3 As Integer
Dim W1, W2, W3 As Integer
Private myFontBold12 As New Font("Tahoma", 12, FontStyle.Bold)
Private myFontDefault8 As New Font("Tahoma", 8, FontStyle.Regular)
Private myFontBold15 As New Font("Tahoma", 15, FontStyle.Bold)
Private myFontBold24 As New Font("Comic Sans MS", 24, FontStyle.Bold)
Private myFontDefault20 As New Font("Tahoma", 20, FontStyle.Regular)
Private myFontDefault12 As New Font("Tahoma", 10, FontStyle.Regular)
Dim Y As Integer
Dim tableFont, titlefont, headfont As Font
Private MyPosY As Single
Private myCurrentPage As Integer
Dim str As String
Private Sub MyPrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles MyPrintDocument.PrintPage
Dim linesPerPage As Single = 0
'RK> Add a page to page counter
myCurrentPage += 0
MyPosY = CSng(e.MarginBounds.Top)
'RK> Set horizontal start position
LoadImage()
'print pageFoot
InvoiceFooter(sender, e)
'######
'print a background
Try
e.Graphics.DrawImage(PictureBox1.Image, X2 + 450, 20) 'link-recht , hoogte
Catch ex As Exception
PictureBox1.Image = My.Resources.PVPLogo 'PictureBox1.Image
e.Graphics.DrawImage(PictureBox1.Image, X2 + 450, 20) 'link-recht , hoogte
End Try
' informatie en Datum
e.Graphics.DrawString("CompanyName: ", myFontBold24, Brushes.Red, X2 - 10, Y + 90) 'X2 vanuit links - Y = Hoogte
e.Graphics.DrawString(TextBox1.Text, myFontBold24, Brushes.Black, X2 + 240, Y + 90) 'Maam bedrijf
e.Graphics.DrawString("ShopName " & TextBox4.Text, myFontBold24, Brushes.Green, X2 - 10, Y + 150)
e.Graphics.DrawString("Datum : " & Format(Date.Today, "dd-MM-yyyy") & " " & Format(TimeOfDay, " HH:mm:ss"), myFontBold12, Brushes.Black, X1 + 90, Y + 1100)
End Sub
Public Sub LoadImage()
Try
'PictureBox3.Image = Image.FromFile(TextBox12.Text)
Catch ex As Exception
'Return
End Try
End Sub
Private myStrFormat As StringFormat
Private Sub InvoiceFooter(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
'Overigge informatie
Dim tmpRect As RectangleF
Dim tmpPen As Pen
Dim tmpText As String
Dim tmpW As Single
Dim tmpH As Single
Dim tmpX As Single
Dim tmpY As Single
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left)
'tmpY = CSng(myPosY)
tmpY = CSng(e.MarginBounds.Bottom - 950)
'RK> Add page title
tmpPen = New Pen(Color.Black)
e.Graphics.DrawLine(tmpPen, tmpX, tmpY, e.MarginBounds.Right, tmpY) 'Lijn Boven
'RK> Add space below
MyPosY += 5
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left)
'tmpY = CSng(myPosY)
tmpY = CSng(e.MarginBounds.Bottom - 100)
'RK> Add page title
tmpPen = New Pen(Color.Black)
e.Graphics.DrawLine(tmpPen, tmpX, tmpY, e.MarginBounds.Right, tmpY) 'Lijn Onder
'RK> Add space below
MyPosY += 5
'RK> Contener1
tmpText = "Contener1 " & TextBox2.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY)
tmpY = CSng(e.MarginBounds.Bottom - 900)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener2
tmpText = "Contener2 " & TextBox3.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 860)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener3
tmpText = "Contener3 " & TextBox4.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 820)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener4
tmpText = "Contener4 " & TextBox5.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 780)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener5
tmpText = "Contener5 " & TextBox6.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 740)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener6
tmpText = "Contener6 " & TextBox7.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 700)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener7
tmpText = "Contener7 " & TextBox8.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 660)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
'RK> Contener8
tmpText = "Contener8 " & TextBox9.Text
'RK> X / Y positions
tmpX = CSng(e.MarginBounds.Left + 250)
tmpY = CSng(MyPosY + 20)
tmpY = CSng(e.MarginBounds.Bottom - 620)
'RK> Add page title
tmpRect = New RectangleF(tmpX, tmpY, tmpW, tmpH)
e.Graphics.DrawString(tmpText, myFontDefault20, New SolidBrush(Color.Black), tmpRect)
End Sub
#End Region
End Class