Public Class Form1
Dim rs As Integer = 99 'عدد الصفوف بالكامل
Dim rpp As Integer = 20 'عدد الصفوف في كل صفحة
Dim ps As Integer = Math.Ceiling(rs / rpp) 'عدد الصفحات
Dim p As Integer = 1 'رقم الصفحة
Dim r As Integer = 1 'رقم الصف
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
p = 1 'رقم الصفحة
r = 1 'رقم الصف
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
p = 1 'رقم الصفحة
r = 1 'رقم الصف
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
Dim hieght As Integer = 100
Dim font1 As New Font("Myriad Droid", 20, FontStyle.Regular, GraphicsUnit.Pixel)
Dim font2 As New Font("Myriad Droid", 25, FontStyle.Regular, GraphicsUnit.Pixel)
Dim rec As New Rectangle(660, 70, 150, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec)
e.Graphics.DrawRectangle(Pens.Black, rec)
e.Graphics.DrawString("رقم الفاتورة", font1, Brushes.Black, rec, sf)
Dim rec1 As New Rectangle(450, 70, 200, 40)
e.Graphics.FillRectangle(Brushes.White, rec1)
e.Graphics.DrawRectangle(Pens.Black, rec1)
e.Graphics.DrawString("0000000000", font1, Brushes.Black, rec1, sf)
Dim rec13 As New Rectangle(230, 70, 150, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec13)
e.Graphics.DrawRectangle(Pens.Black, rec13)
e.Graphics.DrawString("تاريخ الفاتورة", font1, Brushes.Black, rec13, sf)
Dim rec14 As New Rectangle(20, 70, 200, 40)
e.Graphics.FillRectangle(Brushes.White, rec14)
e.Graphics.DrawRectangle(Pens.Black, rec14)
e.Graphics.DrawString("13/06/1988", font1, Brushes.Black, rec14, sf)
Dim rec2 As New Rectangle(660, 120, 150, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec2)
e.Graphics.DrawRectangle(Pens.Black, rec2)
e.Graphics.DrawString("اسم الزبون", font1, Brushes.Black, rec2, sf)
Dim rec3 As New Rectangle(450, 120, 200, 40)
e.Graphics.FillRectangle(Brushes.White, rec3)
e.Graphics.DrawRectangle(Pens.Black, rec3)
e.Graphics.DrawString("صبري", font1, Brushes.Black, rec3, sf)
Dim rec4 As New Rectangle(10, 170, 800, 60)
e.Graphics.FillRectangle(Brushes.White, rec4)
e.Graphics.DrawRectangle(Pens.Black, rec4)
e.Graphics.DrawString("سوق زيد لبيع المواد الغذائية بالجملة", font2, Brushes.Black, rec4, sf)
Dim rec15 As New Rectangle(20, 120, 200, 40)
e.Graphics.FillRectangle(Brushes.White, rec15)
e.Graphics.DrawRectangle(Pens.Black, rec15)
e.Graphics.DrawString("صفحة " & p & " من " & ps, font1, Brushes.Black, rec15, sf)
Dim rec5 As New Rectangle(10, 240, 150, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec5)
e.Graphics.DrawRectangle(Pens.Black, rec5)
e.Graphics.DrawString("الاجمالي", font1, Brushes.Black, rec5, sf)
Dim rec6 As New Rectangle(160, 240, 120, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec6)
e.Graphics.DrawRectangle(Pens.Black, rec6)
e.Graphics.DrawString("الكمية", font1, Brushes.Black, rec6, sf)
Dim rec7 As New Rectangle(280, 240, 150, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec7)
e.Graphics.DrawRectangle(Pens.Black, rec7)
e.Graphics.DrawString("سعر الصندوق", font1, Brushes.Black, rec7, sf)
Dim rec8 As New Rectangle(430, 240, 340, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec8)
e.Graphics.DrawRectangle(Pens.Black, rec8)
e.Graphics.DrawString("الصــــــنف", font1, Brushes.Black, rec8, sf)
Dim rec12 As New Rectangle(770, 240, 40, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, rec12)
e.Graphics.DrawRectangle(Pens.Black, rec12)
e.Graphics.DrawString("ر", font1, Brushes.Black, rec12, sf)
'/////////////////// سيكون هنا وسط الفاتورة
Dim cnt = 280
For i = 0 To rpp - 1
Dim w1 As New Rectangle(10, cnt, 150, 40)
e.Graphics.FillRectangle(Brushes.White, w1)
e.Graphics.DrawRectangle(Pens.Black, w1)
e.Graphics.DrawString("", font1, Brushes.Black, w1, sf)
Dim w2 As New Rectangle(160, cnt, 120, 40)
e.Graphics.FillRectangle(Brushes.White, w2)
e.Graphics.DrawRectangle(Pens.Black, w2)
e.Graphics.DrawString("", font1, Brushes.Black, w2, sf)
Dim w3 As New Rectangle(280, cnt, 150, 40)
e.Graphics.FillRectangle(Brushes.White, w3)
e.Graphics.DrawRectangle(Pens.Black, w3)
e.Graphics.DrawString(" ", font1, Brushes.Black, w3, sf)
Dim w4 As New Rectangle(430, cnt, 380, 40)
e.Graphics.FillRectangle(Brushes.White, w4)
e.Graphics.DrawRectangle(Pens.Black, w4)
e.Graphics.DrawString("", font1, Brushes.Black, w4, sf)
Dim w5 As New Rectangle(770, cnt, 40, 40)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, w5)
e.Graphics.DrawRectangle(Pens.Black, w5)
e.Graphics.DrawString(r, font1, Brushes.Black, w5, sf)
cnt = cnt + 40
r += 1
If r > rs Then Exit For
Next
If p < ps Then
p += 1
e.HasMorePages = True
Exit Sub
End If
'/////////////////// وسط الفاتورة
Dim rec9 As New Rectangle(10, cnt, 150, 40)
e.Graphics.FillRectangle(Brushes.White, rec9)
e.Graphics.DrawRectangle(Pens.Black, rec9)
e.Graphics.DrawString("0000000", font1, Brushes.Black, rec9, sf)
Dim rec10 As New Rectangle(160, cnt, 120, 40)
e.Graphics.FillRectangle(Brushes.White, rec10)
e.Graphics.DrawRectangle(Pens.Black, rec10)
e.Graphics.DrawString("00000000", font1, Brushes.Black, rec10, sf)
Dim rec11 As New Rectangle(280, cnt, 530, 40)
e.Graphics.FillRectangle(Brushes.White, rec11)
e.Graphics.DrawRectangle(Pens.Black, rec11)
e.Graphics.DrawString("الإجمــــــــــــــــــــــالي", font1, Brushes.Black, rec11, sf)
End Sub
End Class