تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] سؤال حول طباعة محتويات ال DataGrid
#1
لدي مشروع بيانات افراد اكتمل حتي مرحلة البحث فقط استوقفني ال 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.WidthDouble) / CType(iTotalWidthDouble) * CType(iTotalWidthDouble) * (CType(e.MarginBounds.WidthDouble) / CType(iTotalWidthDouble)), Double)), Integer)

                    
iHeaderHeight CType((e.Graphics.MeasureString(Gridcol.HeaderTextGridcol.InheritedStyle.FontiTmpWidth).Height) + 11Integer)

                    
'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.FontFontStyle.Bold), Brushes.Blacke.MarginBounds.Left + (e.MarginBounds.Width e.Graphics.MeasureString(strDate, New Font(DataGridView1.FontFontStyle.Regular), e.MarginBounds.Width).Width), e.MarginBounds.Top e.Graphics.MeasureString("Customer Summary", New Font(New Font(DataGridView1.FontFontStyle.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.ValueThen

                            e
.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font, New SolidBrush(Cel.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), CType(iTopMarginSingle), CType(arrColumnWidths(iCount), Integer), CType(iCellHeightSingle)), 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.OKMessageBoxIcon.Error)

        
End Try 

عندما اعمل معاينة للصفحة تطلع البيانات في نصف الصفحة
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
سؤال حول طباعة محتويات ال DataGrid - بواسطة mozafar - 14-09-13, 05:52 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم