لدي مشروع بيانات افراد اكتمل حتي مرحلة البحث فقط استوقفني ال Previewdailog ياريت حد يمدني بالكود الخاص باعداد الصفحة الذي يتضمن اعداد الاعمدة والصفوف والخط الخ
عندما اعمل معاينة للصفحة تطلع البيانات في نصف الصفحة
PHP كود :
Try
'Set the left margin
Dim iLeftMargin As Integer = e.MarginBounds.Left
'Set the top margin
Dim iTopMargin As Integer = e.MarginBounds.Top
'Whether more pages have to print or not
Dim bMorePagesToPrint As Boolean = False
Dim iTmpWidth As Integer = 0
printFont = New Font("Arial", 10)
'For the first page to print set the cell width and header height
If bFirstPage = True Then
For Each Gridcol As DataGridViewColumn In DataGridView1.Columns
iTmpWidth = CType(Math.Floor(CType(CType(Gridcol.Width, Double) / CType(iTotalWidth, Double) * CType(iTotalWidth, Double) * (CType(e.MarginBounds.Width, Double) / CType(iTotalWidth, Double)), Double)), Integer)
iHeaderHeight = CType((e.Graphics.MeasureString(Gridcol.HeaderText, Gridcol.InheritedStyle.Font, iTmpWidth).Height) + 11, Integer)
'Save width and height of headers
arrColumnLefts.Add(iLeftMargin)
arrColumnWidths.Add(iTmpWidth)
iLeftMargin = iLeftMargin + iTmpWidth
Next
End If
'Loop till all the grid rows not get printed
While iRow <= DataGridView1.Rows.Count - 1
Dim GridRow As DataGridViewRow = DataGridView1.Rows(iRow)
'Set the cell height
iCellHeight = GridRow.Height + 5
Dim iCount As Integer = 0
'Check whether the current page settings allo more rows to print
If iTopMargin + iCellHeight >= e.MarginBounds.Height + e.MarginBounds.Top Then
bNewPage = True
bFirstPage = False
bMorePagesToPrint = True
Exit While
Else
If bNewPage = True Then
'Draw header
e.Graphics.DrawString("نتيجة البحث", New Font(DataGridView1.Font, FontStyle.Regular), Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top - e.Graphics.MeasureString("Customer Summary", New Font(DataGridView1.Font, FontStyle.Regular), e.MarginBounds.Width).Height - 13)
Dim strDate As String = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString()
'Draw Date
e.Graphics.DrawString(strDate, New Font(DataGridView1.Font, FontStyle.Bold), Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(strDate, New Font(DataGridView1.Font, FontStyle.Regular), e.MarginBounds.Width).Width), e.MarginBounds.Top - e.Graphics.MeasureString("Customer Summary", New Font(New Font(DataGridView1.Font, FontStyle.Regular), FontStyle.Regular), e.MarginBounds.Width).Height - 13)
'Draw Columns
iTopMargin = e.MarginBounds.Top
For Each GridCol As DataGridViewColumn In DataGridView1.Columns
e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight))
e.Graphics.DrawRectangle(Pens.Green, New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight))
e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font, New SolidBrush(GridCol.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight), strFormat)
iCount = iCount + 1
Next GridCol
bNewPage = False
iTopMargin += iHeaderHeight
End If
iCount = 0
'Draw Columns Contents
For Each Cel As DataGridViewCell In GridRow.Cells
If Not IsDBNull(Cel.Value) Then
e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font, New SolidBrush(Cel.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), CType(iTopMargin, Single), CType(arrColumnWidths(iCount), Integer), CType(iCellHeight, Single)), strFormat)
End If
'Drawing Cells Borders
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iCellHeight))
iCount = iCount + 1
Next
End If
iRow = iRow + 1
iTopMargin = iTopMargin + iCellHeight
End While
'If more lines exist, print another page.
If bMorePagesToPrint = True 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
عندما اعمل معاينة للصفحة تطلع البيانات في نصف الصفحة