PrintPreviewControl & Form Design working differently on another OS. VB.NET

461 views Asked by At

im writing an app for accountings of small hotel, i'm working with Visual Studio 2013, on OS: windows 10 (Laptop). After finishing the app just published it using publish wizard, then everything was going great till i copied the published files to another computer contains OS: Windows 7 SP1, the app worked successfully but with a little changes in form design and while preview reports printing.

Here's two pictures to explain what is exactly the problem... enter image description here enter image description here

If anyone could explain what's going on and what to do to solve this issue would be respected.

Here's my class which contains printpreviewcontrol code:

Private mRow As Integer = 0
Private newpage As Boolean = True
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Try
        Dim font36 = New Font("Playball", 36, FontStyle.Regular)
        Dim font8 = New Font("Lora", 8, FontStyle.Regular)
        Dim font20 = New Font("Lora", 20, FontStyle.Underline)
        Dim font16 = New Font("Lora", 16, FontStyle.Regular)
        e.Graphics.DrawString("Riviera Beach Chalets", font36, Brushes.Black, New Rectangle(150, 25, 800, 100))
        e.Graphics.DrawString("Accounting Reports", font20, Brushes.Black, New Rectangle(650, 45, 300, 50))

        e.Graphics.FillRectangle(Brushes.MistyRose, New Rectangle(101, 741, 19, 19))
        e.Graphics.DrawString("Accommondation Revenue or Beach Revenue or CoffeeShop Revenue is 0", font8, Brushes.Black, New Rectangle(125, 745, 500, 30))
        e.Graphics.DrawString("Amount Received Total :", font16, Brushes.Black, New Rectangle(570, 735, 500, 50))
        e.Graphics.DrawString(Report_Database.reporttot, font16, Brushes.Black, New Rectangle(850, 735, 500, 50))


        ' sets it to show '...' for long text
        Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
        fmt.LineAlignment = StringAlignment.Center
        fmt.Trimming = StringTrimming.EllipsisCharacter
        Dim y As Int32 = e.MarginBounds.Top
        Dim rc As Rectangle
        Dim x As Int32
        Dim h As Int32 = 0
        Dim row As DataGridViewRow

        ' print the header text for a new page
        '   use a grey bg just like the control
        If newpage Then
            row = Report_Database.DataGridView1.Rows(mRow)

            x = 50
            For Each cell As DataGridViewCell In row.Cells
                ' since we are printing the control's view,
                ' skip invidible columns
                If cell.Visible Then
                    rc = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)

                    e.Graphics.FillRectangle(Brushes.LightGray, rc)
                    e.Graphics.DrawRectangle(Pens.Black, rc)

                    ' reused in the data pront - should be a function
                    Select Case Report_Database.DataGridView1.Columns(cell.ColumnIndex).DefaultCellStyle.Alignment
                        Case DataGridViewContentAlignment.BottomRight,
                             DataGridViewContentAlignment.MiddleRight
                            fmt.Alignment = StringAlignment.Far
                            rc.Offset(-1, 0)
                        Case DataGridViewContentAlignment.BottomCenter,
                            DataGridViewContentAlignment.MiddleCenter
                            fmt.Alignment = StringAlignment.Center
                        Case Else
                            fmt.Alignment = StringAlignment.Near
                            rc.Offset(2, 0)
                    End Select

                    e.Graphics.DrawString(Report_Database.DataGridView1.Columns(cell.ColumnIndex).HeaderText,
                                                Report_Database.DataGridView1.Font, Brushes.Black, rc, fmt)
                    x += rc.Width
                    h = Math.Max(h, rc.Height)
                End If
            Next
            y += h

        End If
        newpage = False

        ' now print the data for each row
        Dim thisNDX As Int32
        For thisNDX = mRow To Report_Database.DataGridView1.RowCount - 1
            ' no need to try to print the new row
            If Report_Database.DataGridView1.Rows(thisNDX).IsNewRow Then Exit For

            row = Report_Database.DataGridView1.Rows(thisNDX)

            h = 0

            ' reset X for data
            x = 50

            ' print the data
            For Each cell As DataGridViewCell In row.Cells
                If cell.Visible Then
                    rc = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)

                    ' SAMPLE CODE: How To 
                    ' up a RowPrePaint rule
                    If Val(row.Cells(2).Value) = 0 Or Val(row.Cells(3).Value) = 0 Or Val(row.Cells(4).Value) = 0 Then
                        Using br As New SolidBrush(Color.MistyRose)
                            e.Graphics.FillRectangle(br, rc)
                        End Using

                    End If

                    e.Graphics.DrawRectangle(Pens.Black, rc)

                    Select Case Report_Database.DataGridView1.Columns(cell.ColumnIndex).DefaultCellStyle.Alignment
                        Case DataGridViewContentAlignment.BottomRight,
                             DataGridViewContentAlignment.MiddleRight
                            fmt.Alignment = StringAlignment.Far
                            rc.Offset(-1, 0)
                        Case DataGridViewContentAlignment.BottomCenter,
                            DataGridViewContentAlignment.MiddleCenter
                            fmt.Alignment = StringAlignment.Center
                        Case Else
                            fmt.Alignment = StringAlignment.Near
                            rc.Offset(2, 0)
                    End Select

                    e.Graphics.DrawString(cell.FormattedValue.ToString(),
                                          Report_Database.DataGridView1.Font, Brushes.Black, rc, fmt)

                    x += rc.Width
                    h = Math.Max(h, rc.Height)
                End If

            Next
            y += h
            ' next row to print
            mRow = thisNDX + 1

            If y + h > e.MarginBounds.Bottom Then
                e.HasMorePages = True
                ' mRow -= 1   causes last row to rePrint on next page
                newpage = True
                Button1.Enabled = True
                Button4.Enabled = True
                If mRow = Report_Database.DataGridView1.RowCount Then
                    e.HasMorePages = False
                    Exit Sub
                End If
                Return
            End If
        Next
    Catch ex As Exception
        MsgBox(ex.ToString, MsgBoxStyle.Critical)
    End Try
0

There are 0 answers