الكود هو الخاص بطباعة الجريد فيو
وهو ممتاز جدا ولكن توجد مشكلة واحدة وهى عدم القدرة على كتابة بيانات التقرير اعلى الصفحة
مثل اسم المحل
اسم العميل
تاريخ الشراء
وغيرة
مع العلم اننى قمت بالتعديل علية والاستقادة منه بشكل كبير جدا ولكن اريد التحكم فى المساحة بين اعلى الصفحة وبداية عرض بيانات الجريد فيو
Private strFormat As StringFormat
Private arrColumnLefts As New ArrayList()
Private arrColumnWidths As New ArrayList()
Private iCellHeight As Integer = 0
Private iTotalWidth As Integer = 0
Private iRow As Integer = 0
Private bFirstPage As Boolean = False
Private bFirstPage2 As Boolean = False
Private bNewPage As Boolean = False
Private iHeaderHeight As Integer = 0
Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
Try
strFormat = New StringFormat()
strFormat.Alignment = StringAlignment.Near
strFormat.LineAlignment = StringAlignment.Center
strFormat.Trimming = StringTrimming.EllipsisCharacter
arrColumnLefts.Clear()
arrColumnWidths.Clear()
iCellHeight = 0
iRow = 0
bFirstPage = True
bFirstPage2 = True
bNewPage = True
iTotalWidth = 0
For Each dgvGridCol As DataGridViewColumn In DGV.Columns
iTotalWidth += dgvGridCol.Width
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
Dim fr As New StringFormat(StringFormatFlags.DirectionRightToLeft)
'نوع الخط وحجم الخط واللون
Dim f88 As Font = New System.Drawing.Font("Arial", 9, FontStyle.Bold)
Dim f12 As Font = New System.Drawing.Font("Arial", 12, FontStyle.Bold)
Dim f As Font = New System.Drawing.Font("Arial", 13, FontStyle.Bold)
Dim f18 As Font = New System.Drawing.Font("Arial", 18, FontStyle.Bold)
e.Graphics.DrawImage(Form1.PictureBox2.Image, 110, 250, 600, 600)
e.Graphics.DrawImage(Form1.PictureBox1.Image, 50, 30, 150, 120)
Dim iLeftMargin As Integer = e.MarginBounds.Left
Dim iTopMargin As Integer = e.MarginBounds.Top
Dim bMorePagesToPrint As Boolean = False
Dim iTmpWidth As Integer = 0
If bFirstPage Then
For Each GridCol As DataGridViewColumn In DGV.Columns
iTmpWidth = Math.Floor(GridCol.Width / iTotalWidth * iTotalWidth * e.MarginBounds.Width / iTotalWidth)
iHeaderHeight = e.Graphics.MeasureString(GridCol.HeaderText, GridCol.InheritedStyle.Font, iTmpWidth).Height + 20
arrColumnLefts.Add(iLeftMargin)
arrColumnWidths.Add(iTmpWidth)
iLeftMargin += iTmpWidth
Next
End If
While iRow <= DGV.Rows.Count - 1
DGV.Rows(iRow).Cells(0).Style.Font = (f)
DGV.Rows(iRow).Cells(2).Style.Font = (f88)
Dim x4 As Integer
Dim xl As Long
xl = Len(DGV.Rows(iRow).Cells(2).Value.ToString())
x4 = xl / 50
x4 = x4 + 1
x4 = x4 * 22
Dim GridRow As DataGridViewRow = DGV.Rows(iRow)
iCellHeight = GridRow.Height + x4
Dim iCount As Integer = 0
If iTopMargin + iCellHeight >= e.MarginBounds.Height + e.MarginBounds.Top Then
bNewPage = True
bFirstPage = False
bFirstPage2 = False
bMorePagesToPrint = True
Exit While
Else
If bNewPage Then
e.Graphics.DrawString("--------------", New Font(DGV.Font, FontStyle.Bold), Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top - e.Graphics.MeasureString("Customer Summary", New Font(DGV.Font, FontStyle.Bold), e.MarginBounds.Width).Height - 13)
"
e.Graphics.DrawString(datname, f18, Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(datname, New Font(DGV.Font, FontStyle.Bold), e.MarginBounds.Width).Width) - 90, e.MarginBounds.Top - e.Graphics.MeasureString("Customer Summary", New Font(DGV.Font, FontStyle.Bold), e.MarginBounds.Width).Height - 80)
e.Graphics.DrawString(datname2, f28, Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(datname2, New Font(DGV.Font, FontStyle.Bold), e.MarginBounds.Width).Width) - 100, e.MarginBounds.Top - e.Graphics.MeasureString("Customer Summary", New Font(DGV.Font, FontStyle.Bold), e.MarginBounds.Width).Height - 50)
Dim strDate As String = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString()
e.Graphics.DrawString(strDate, New Font(DGV.Font, FontStyle.Bold), Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(strDate, New Font(DGV.Font, FontStyle.Bold), e.MarginBounds.Width).Width), e.MarginBounds.Top - e.Graphics.MeasureString("Customer Summary", New Font(New Font(DGV.Font, FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13)
iTopMargin = e.MarginBounds.Top
For Each GridCol As DataGridViewColumn In DGV.Columns
e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(DirectCast(arrColumnLefts(iCount), Integer), iTopMargin, DirectCast(arrColumnWidths(iCount), Integer), iHeaderHeight))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(DirectCast(arrColumnLefts(iCount), Integer), iTopMargin, DirectCast(arrColumnWidths(iCount), Integer), iHeaderHeight))
e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font, New SolidBrush(GridCol.InheritedStyle.ForeColor), New RectangleF(DirectCast(arrColumnLefts(iCount), Integer), iTopMargin, DirectCast(arrColumnWidths(iCount), Integer), iHeaderHeight), strFormat)
System.Math.Max(System.Threading.Interlocked.Increment(iCount), iCount - 1)
Next
bNewPage = False
iTopMargin += iHeaderHeight
End If
iCount = 0
For Each Cel As DataGridViewCell In GridRow.Cells
If Not Cel.Value Is Nothing Then
e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font, New SolidBrush(Cel.InheritedStyle.ForeColor), New RectangleF(DirectCast(arrColumnLefts(iCount), Integer), DirectCast(iTopMargin, Integer), DirectCast(arrColumnWidths(iCount), Integer), DirectCast(iCellHeight, Integer)), strFormat)
End If
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(DirectCast(arrColumnLefts(iCount), Integer), iTopMargin, DirectCast(arrColumnWidths(iCount), Integer), iCellHeight))
System.Math.Max(System.Threading.Interlocked.Increment(iCount), iCount - 1)
Next
End If
System.Math.Max(System.Threading.Interlocked.Increment(iRow), iRow - 1)
iTopMargin += iCellHeight
End While
If bMorePagesToPrint Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
Catch exc As Exception
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub