تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] اخر تعديل بالكلاس
#1
السلام عليكم

قام احد الاخوة بارك اللة فية بتعديل كلاس الطباعة من اليمين الي اليسار وباقي تعديل اخير فقط

الكلاس يطبع كل محتوي الداتا جريد كلة

الكلاس مكون من الداتا جريد وال footer

- المطلوب ان يكون footer بعد اخر صف بالداتا جريد- لو في صفحة واحدة للطباعة ومحتوي الصفحة اقترب من نهاية الصفحة الاولي واضيف الية footer يظهر باعتبار انة انتقل للصفحة التالية بكل محتواة     

:   حيث بالكلاس لايظهر الا محتوي المقبول بالصفحة الاولي

او لو في اكتر من صفحة يظهر باخر صفحة فقط مع مراعاة الشرط  السابق

الكلاس


PHP كود :
Imports System.Drawing.Printing
Module DataGridViewPrinter

    Public DataGridViewToPrint 
As New DataGridView

    Public DefaultPageSettings 
As PageSettings = New PageSettings()

 
   Public WithEvents DocToPrint As New PrintDocument

    Private lPageNo 
As String ""
 
   Private sPageNo As String ""
 
   Private oStringFormat As StringFormat
    Private oStringFormatComboBox 
As StringFormat
    Private oButton 
As Button
    Private oCheckbox 
As CheckBox
    Private oComboBox 
As ComboBox
    Private nTotalWidth 
As Int16
    Private nRowPos 
As Int16
    Private NewPage 
As Boolean
    Private nPageNo 
As Int16
    Private Header 
As String
    Private FooterComment 
As String ""

 
   Public Sub StartPrint(ByVal GridToPrint As DataGridViewByVal PrintAsLandscape As BooleanByVal ShowPrintPreview As BooleanByVal HeaderToPrint As StringByVal CommentToPrint As String)

 
       DataGridViewToPrint GridToPrint
        Header 
HeaderToPrint
        FooterComment 
CommentToPrint

        
'DataGridViewToPrint.Columns(2).Visible = False ' Use to hide a col. (index no.)

 
       ' Set up Default Page Settings
        DocToPrint.DefaultPageSettings.Landscape = PrintAsLandscape
        DocToPrint.DefaultPageSettings.Margins.Left = 25
        DocToPrint.DefaultPageSettings.Margins.Right = 75
        DocToPrint.DefaultPageSettings.Margins.Top = 25
        DocToPrint.DefaultPageSettings.Margins.Bottom = 75

        DocToPrint.OriginAtMargins = True ' 
takes margins into account

        If ShowPrintPreview 
True Then

            Dim dlgPrintPreview 
As New PrintPreviewDialog

            dlgPrintPreview
.ClientSize = New System.Drawing.Size(600600)
 
           dlgPrintPreview.Document DocToPrint ' Previews print
            dlgPrintPreview.ShowDialog()

        Else

            ' 
 Allow the user to choose a printer and specify other settings.
 
           Dim dlgPrint As New PrintDialog

            With dlgPrint
                
.AllowSelection False
                
.ShowNetwork False
                
.AllowCurrentPage True
                
.AllowSomePages True
                
.Document DocToPrint
            End With

            
'  If the user clicked OK, print the document.
            If dlgPrint.ShowDialog = Windows.Forms.DialogResult.OK Then
                DocToPrint.Print()
            End If

        End If

    End Sub

    Public Sub DocToPrint_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles DocToPrint.BeginPrint

        oStringFormat = New StringFormat
        oStringFormat.Alignment = StringAlignment.Far
        oStringFormat.LineAlignment = StringAlignment.Center
        oStringFormat.Trimming = StringTrimming.EllipsisCharacter

        oStringFormatComboBox = New StringFormat
        oStringFormatComboBox.LineAlignment = StringAlignment.Center
        oStringFormatComboBox.FormatFlags = StringFormatFlags.NoWrap
        oStringFormatComboBox.Trimming = StringTrimming.EllipsisCharacter

        oButton = New Button
        oCheckbox = New CheckBox
        oComboBox = New ComboBox

        nTotalWidth = 0

        For i As Integer = DataGridViewToPrint.Columns.Count - 1 To 0 Step -1
            If DataGridViewToPrint.Columns(i).Visible = True Then ' 
Prints only Visible columns
                nTotalWidth 
+= DataGridViewToPrint.Columns(i).Width
            End 
If
 
       Next
        
'For Each oColumn As DataGridViewColumn In DataGridViewToPrint.Columns
        ' 
   If oColumn.Visible True Then ' Prints only Visible columns
        ' 
       nTotalWidth += oColumn.Width
        
'    End If
        '
Next

        nPageNo 
1
        NewPage 
True
        nRowPos 
0

    End Sub

    
    Public Sub DocToPrint_PrintPage
(ByVal sender As ObjectByVal e As System.Drawing.Printing.PrintPageEventArgsHandles DocToPrint.PrintPage

        Static oColumnLefts 
As New ArrayList
        Static oColumnWidths 
As New ArrayList
        Static oColumnTypes 
As New ArrayList
        Static nHeight 
As Int16

        Dim nWidth
inRowsPerPage As Int16
        Dim nTop 
As Int16 e.MarginBounds.Top
        Dim nLeft 
As Int16 e.MarginBounds.Left

        If nPageNo 
1 Then

            oColumnLefts
.Clear()
 
           oColumnWidths.Clear()
 
           oColumnTypes.Clear()
 
         
            For Each oColumn 
As DataGridViewColumn In DataGridViewToPrint.Columns
                If oColumn
.Visible True Then
                    nWidth 
CType(Math.Floor(oColumn.Width nTotalWidth nTotalWidth * (e.MarginBounds.Width nTotalWidth)), Int16)
 
                   nHeight e.Graphics.MeasureString(oColumn.HeaderTextoColumn.InheritedStyle.FontnWidth).Height 11

                    oColumnLefts
.Add(nLeft)
 
                   oColumnWidths.Add(nWidth)
 
                   oColumnTypes.Add(oColumn.GetType)
 
                   nLeft += nWidth
                End 
If
 
           Next

        End 
If

 
       Do While nRowPos DataGridViewToPrint.Rows.Count 1

            Dim oRow 
As DataGridViewRow DataGridViewToPrint.Rows(nRowPos)

 
           If nTop nHeight >= e.MarginBounds.Height e.MarginBounds.Top Then

                
'  DrawFooter(e, nRowsPerPage)

                NewPage = True
                nPageNo += 1
                e.HasMorePages = True
                Exit Sub

            Else

                If NewPage Then

                    ' 
Draw Columns
                    
'  nTop = e.MarginBounds.Top + 50
                    i = 0
                    For ii As Integer = DataGridViewToPrint.Columns.Count - 1 To 0 Step -1
                        If DataGridViewToPrint.Columns(ii).Visible = True Then
                            e.Graphics.FillRectangle(New SolidBrush(Drawing.Color.LightGray), New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight))
                            e.Graphics.DrawRectangle(Pens.LightGray, New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight))
                            e.Graphics.DrawString(DataGridViewToPrint.Columns(ii).HeaderText, DataGridViewToPrint.Columns(ii).InheritedStyle.Font, New SolidBrush(DataGridViewToPrint.Columns(ii).InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i), nTop, oColumnWidths(i), nHeight), oStringFormat)
                            i += 1
                        End If

                    Next
                    NewPage = False

                End If

                nTop += nHeight
                i = 0
                For Each oCell As DataGridViewCell In oRow.Cells
                    If oCell.Visible = True Then
                        If oColumnTypes(i) Is GetType(DataGridViewTextBoxColumn) OrElse oColumnTypes(i) Is GetType(DataGridViewLinkColumn) Then

                            e.Graphics.DrawString(oCell.Value.ToString, oCell.InheritedStyle.Font, New SolidBrush(oCell.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i), nTop, oColumnWidths(i), nHeight), oStringFormat)

                        ElseIf oColumnTypes(i) Is GetType(DataGridViewButtonColumn) Then

                            oButton.Text = oCell.Value.ToString
                            oButton.Size = New Size(oColumnWidths(i), nHeight)
                            Dim oBitmap As New Bitmap(oButton.Width, oButton.Height)
                            oButton.DrawToBitmap(oBitmap, New Rectangle(0, 0, oBitmap.Width, oBitmap.Height))
                            e.Graphics.DrawImage(oBitmap, New Point(oColumnLefts(i), nTop))

                        ElseIf oColumnTypes(i) Is GetType(DataGridViewCheckBoxColumn) Then

                            oCheckbox.Size = New Size(14, 14)
                            oCheckbox.Checked = CType(oCell.Value, Boolean)
                            Dim oBitmap As New Bitmap(oColumnWidths(i), nHeight)
                            Dim oTempGraphics As Graphics = Graphics.FromImage(oBitmap)
                            oTempGraphics.FillRectangle(Brushes.White, New Rectangle(0, 0, oBitmap.Width, oBitmap.Height))
                            oCheckbox.DrawToBitmap(oBitmap, New Rectangle(CType((oBitmap.Width - oCheckbox.Width) / 2, Int32), CType((oBitmap.Height - oCheckbox.Height) / 2, Int32), oCheckbox.Width, oCheckbox.Height))
                            e.Graphics.DrawImage(oBitmap, New Point(oColumnLefts(i), nTop))

                        ElseIf oColumnTypes(i) Is GetType(DataGridViewComboBoxColumn) Then

                            oComboBox.Size = New Size(oColumnWidths(i), nHeight)
                            Dim oBitmap As New Bitmap(oComboBox.Width, oComboBox.Height)
                            oComboBox.DrawToBitmap(oBitmap, New Rectangle(0, 0, oBitmap.Width, oBitmap.Height))
                            e.Graphics.DrawImage(oBitmap, New Point(oColumnLefts(i), nTop))
                            e.Graphics.DrawString(oCell.Value.ToString, oCell.InheritedStyle.Font, New SolidBrush(oCell.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i) + 1, nTop, oColumnWidths(i) - 16, nHeight), oStringFormatComboBox)

                        ElseIf oColumnTypes(i) Is GetType(DataGridViewImageColumn) Then

                            Dim oCellSize As Rectangle = New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight)
                            Dim oImageSize As Size = CType(oCell.Value, Image).Size
                            e.Graphics.DrawImage(oCell.Value, New Rectangle(oColumnLefts(i) + CType(((oCellSize.Width - oImageSize.Width) / 2), Int32), nTop + CType(((oCellSize.Height - oImageSize.Height) / 2), Int32), CType(oCell.Value, Image).Width, CType(oCell.Value, Image).Height))

                        End If

                        e.Graphics.DrawRectangle(Pens.LightGray, New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight))

                        i += 1
                    End If
                Next

            End If

            nRowPos += 1
            nRowsPerPage += 1

        Loop

        DrawFooter(e, nRowsPerPage)

        e.HasMorePages = False

    End Sub

    Public Sub DrawFooter(ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal RowsPerPage As Int32)

        Dim sPageNo As String = nPageNo.ToString + " من "

        If nPageNo = "1" Then
            lPageNo = Math.Ceiling((DataGridViewToPrint.Rows.Count - 1) / RowsPerPage).ToString()
            sPageNo = lPageNo + nPageNo.ToString + " من "
            ' 
Right Align User Name
            e
.Graphics.DrawString(FooterCommentDataGridViewToPrint.FontBrushes.Blacke.MarginBounds.Left + (e.MarginBounds.Width e.Graphics.MeasureString(FooterCommentDataGridViewToPrint.Fonte.MarginBounds.Width).Width), e.MarginBounds.Top e.MarginBounds.Height 25)

 
           ' Left Align - Date/Time
            e.Graphics.DrawString(Now.ToLongDateString + " " + Now.ToShortTimeString, DataGridViewToPrint.Font, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top + e.MarginBounds.Height + 25)

            ' 
Center Page NoInfo
            e
.Graphics.DrawString(sPageNoDataGridViewToPrint.FontBrushes.Blacke.MarginBounds.Left + (e.MarginBounds.Width e.Graphics.MeasureString(sPageNoDataGridViewToPrint.Fonte.MarginBounds.Width).Width) / 2e.MarginBounds.Top e.MarginBounds.Height 25)

 
       Else

            sPageNo 
lPageNo nPageNo.ToString " من " '+ lPageNo
            ' 
Right Align User Name
            e
.Graphics.DrawString(FooterCommentDataGridViewToPrint.FontBrushes.Blacke.MarginBounds.Left + (e.MarginBounds.Width e.Graphics.MeasureString(FooterCommentDataGridViewToPrint.Fonte.MarginBounds.Width).Width), e.MarginBounds.Top e.MarginBounds.Height 450)

 
           ' Left Align - Date/Time
            e.Graphics.DrawString(Now.ToLongDateString + " " + Now.ToShortTimeString, DataGridViewToPrint.Font, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top + e.MarginBounds.Height - 450)

            ' 
Center Page NoInfo
            e
.Graphics.DrawString(sPageNoDataGridViewToPrint.FontBrushes.Blacke.MarginBounds.Left + (e.MarginBounds.Width e.Graphics.MeasureString(sPageNoDataGridViewToPrint.Fonte.MarginBounds.Width).Width) / 2e.MarginBounds.Top e.MarginBounds.Height 450)

 
       End If
 
   End Sub

End Module 
الرد }}}
تم الشكر بواسطة:
#2
ولا رد واحد من الاخوة الاعضاء
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  تعديل على فاتورة مبيعات خالد كامل1 4 124 26-03-24, 10:49 PM
آخر رد: خالد كامل1
  تعديل كود ارسال صورة الى الواتس new_programer 2 170 21-03-24, 10:07 PM
آخر رد: new_programer
  تعديل صب المجموع الكلي والمعدل والتقدير مصمم هاوي 3 173 19-03-24, 01:33 AM
آخر رد: مصمم هاوي
  تعديل طول حقل معين في جميع جداول القاعدة atefkhalf2004 1 108 09-03-24, 03:17 AM
آخر رد: atefkhalf2004
  تعديل بيانات عمود DataGridView دفعة واحدة مصمم هاوي 2 198 05-03-24, 08:27 PM
آخر رد: مصمم هاوي
  ممكن تعديل في كود التفقيط للارقام melad2002 2 365 01-01-24, 08:47 PM
آخر رد: melad2002
  [VB.NET] اريد تعديل في الكود عند طباعة DGV abu_hisham7 1 443 03-12-23, 02:40 AM
آخر رد: abu_hisham7
  [VB.NET] محتاج مساعدة تعديل على كود ZEEN4ZEEN 4 434 08-10-23, 09:11 PM
آخر رد: ZEEN4ZEEN
  محتاج تعديل على سورس كود - حفظ البيانات بدون قاعدة بيانات new_programer 5 680 30-08-23, 12:21 AM
آخر رد: atefkhalf2004
  اريد اضافة متغيراخر داخل Listbox1 احتاج تعديل بسيط moh61 0 354 05-08-23, 02:29 PM
آخر رد: moh61

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


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